I'm trying to generate a directive that embeds an editor (form). The outer controller is able to push the "thing to edit" into the inner directive easily enough, but I'd like the outer controller to know when the form is dirty. My overall template (simplified):
<div ng-controller="outer">
<account-editor account-id="currentID" dirty-flag="isDirty"></account-editor>
</div>
I want to be updating the isDirty flag on the "outer" controller with this directive:
directive('accountEditor',[ 'account', function(account) {
return {
restrict: 'E',
scope: {
accountId: '=',
dirtyFlag: '='
},
link: function($scope, element, attr, ctrl) {
$scope.$watch('accountId', function() {
$scope.accountToEdit = account.getAccount($scope.accountId);
});
// I WANT TO WATCH THE FORM STATE, AND UPDATE dirtyFlag
},
template: '<form><input ng-model="accountToEdit.name"/></form>'
};
}]);
Should I write an additional directive to put on the <form>, use an event, access the DOM directly during link, or something else?
My full code is at http://jsbin.com/amuduro/1/edit, but it includes LOTs more features.