From my understanding, the angular link
function serves the purpose of "registering DOM listeners and updating the DOM."
However, upon examining this example:
app.directive('changecase', function () {
return {
restrict: 'A',
require: 'ngModel',
link: function (scope, element, attrs, ngModel) {
//format text going to user (model to view)
ngModel.$formatters.push(function(value) {
return value.toUpperCase();
});
//format text from the user (view to model)
ngModel.$parsers.push(function(value) {
return value.toLowerCase();
});
}
}
});
I have come across numerous instances where the link function is utilized to "firewall" undesirable values both into and out of the model.
Question
This action does not involve manipulating the DOM or handling listeners.
It appears rather unconventional to place these "firewalls" within the link
function.
Is it indeed the appropriate location for $parsers/$formatters?