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

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -

java - Digest auth with Spring Security using javaconfig -