angularjs - Angular - Use $sanitize on every input -
on server side sanitise coming in.
on angular app client side i've done same in instances e.g. contact forms thinking shouldn't apply every input field?
so i've seen $sanitize('some string')
there way apply @ top app level rather having enter every instance input fields is?
(assuming wise thing - if not keen hear suggestions).
thanks.
you can create directive call "input", apply inputs of app.
inside directive can add parser $ngmodel apply automatically $sanitize when value changes.
it looks this:
myapp.directive('input', function($sanitize) { return { restrict: 'e', require: '?ngmodel', link: function (scope, element, attrs, ngmodel) { if(ngmodel !== undefined){ ngmodel.$parsers.push(function(value){ return $sanitize(value); }); } } }; });
Comments
Post a Comment