I have a directive like so:
.directive('checkMeIfApplyAll', function($timeout) {
return {
link: function(scope, element, attrs) {
scope.$watch(attrs.checkMeIfApplyAll, function(value) {
debugger;
if(value === true) {
element.prop('checked', true);
}
else {
element.prop('checked', false);
}
});
}
};
And here is the corresponding html snippet:
<tr 'ng-repeat'='permission in category.permissions'>
<input type='checkbox' 'ng-model'='permission.show' 'check-me-if-apply-all'= 'category.allChecked'>
</tr>
Notice that if the value of category.allChecked changes, the watcher function is triggered. As you can see, if that value is true, then using jquery, I can check the checkbox. However, as you can see in the html snippet, each checkbox has been assigned a model e.g. 'permission.show'. And what I really want to do is change the model value in the directive and not simply the property of element. How can I access the ng-model attribute of the element inside of the watch function?