I need to access ngModelController of input element to check is it dirty or pristine.
I've managed to do it with directive which grabs ngModel of input to data object associated with element, making it obtainable from anywhere:
app.directive("input", [ function () {
return {
restrict: "E",
replace: false,
scope: false,
require: "ngModel",
link: function (scope, element, attrs, ctrls) {
element.data('ngModelController', ctrls);
}
}
}])
I know it could be modified to make directive as attribute, making it less coupled to 'input' tag.
I use that saved controllers in directives which represent UI elements and have input elements in their markup. I don't use forms because those elements should work in any dom context, and forms imply certain limitations to hierarchy. So i'm using ngModelController to check some stuff required for validation of fields.
But is there any better way to get ngModelController of certain input?