I have a script in an Angular 1.x project where I need to look at the controller form inside the directive in order to perform a fake $ form check. Once the form on the page is dirty, I need to set a flag in the injected service.
Here is the general directory code:
var directiveObject = {
restrict: 'A',
require: '^form',
link: linkerFn,
scope: {
ngConfirm: '&unsavedCallback'
}
};
return directiveObject;
function linkerFn(scope, element, attrs, formCtrl) {
...
scope.$watch('formCtrl.$dirty', function(oldVal, newVal) {
console.log('form property is being watched');
}, true);
...
}
The above only goes into the clock during initialization, so I tried other approaches with the same result:
view the scope of $ parent [formName]. $ dirty (in this case, I pass formName to attrs and set it to local var formName = attrs.formName)
view element.controller () [formName] (same result as above)
SO, , . , , - ( ) .
.
.