This is my current implmentation to fire callback on customVar get change using $watch...
module.directive('mudirective', function() {
return {
scope: {
callback: '&'
},
template: '<h1>Hello</h1><button ng-click="changeVaar()>Click</button>"',
controller: function($scope) {
$scope.customVar = false;
$scope.changeVaar = function() {
// some large logical execution
// which set customeVar
$scope.customVar = '';//some value assgined
};
},
link: function($scope) {
$scope.$watch('customVar', function() {
$scope.callback();
});
}
};
});
But i would like to replace this $watch with setter
...
Can anybody has idea how could it be possible?
OR
Other option to avoid $watch
function but fire callback
on customVar changes.
But callback should be fire once it is confirmed that customVar has changed in directive itself.
customVar
changed? If it is in an input you can just do<input ng-model="customVar" ng-change="callback()"
$scope.callback()
towards the end of$scope.changeVaar = function() {
function after setting the value to$scope.customVar