html
<input type="text" name="usernr" ng-model="userNr" placeholder="user nr"
tabindex="2" ng-usernumber/>
javascript
app.directive('ngUserNumber', function() {
return {
restrict: 'A',
require: 'ngModel',
link: function(scope, elm, attrs, ctrl) {
console.log("inside directive");
ctrl.$parsers.push(function(data) {
console.log("//convert data from view format to model format");
data = data.toString() + " test";
return data; //converted
});
ctrl.$formatters.push(function(data) {
console.log("//convert data from model format to view format");
data = data.toString() + " test";
return data; //converted
});
}
};
});
I would like to replace the data provided by ng-model, with data from inside the directive. But nothing happens. How come the custom directive isn't used?
I followed this doc: http://www.ng-newsletter.com/posts/directives.html
other source: https://stackoverflow.com/a/15346236/489856