First, here is the code:
app.controller('MainCtrl', function($scope) {
$scope.test="Hello!";
$scope.updateFlag = false;
function updateFunc(){
$scope.updateFlag = true;
}
$scope.updateFunc = updateFunc;
});
app.directive('dir1', function(){
return {
scope:{
updateFunc:'='
},
link: function(scope,element,attr,ctrl){
element.bind('click', scope.updateFunc);
}
}
});
app.directive('dir2', function(){
return {
template: '{{privateVal}}',
scope:{
updateFlag:'='
},
link: function(scope,element,attr,ctrl){
scope.privateVal= "Not working!";
scope.$watch(scope.updateFlag, function(newval, oldval){
alert("watch triggered");
if (newval===true){
scope.privateVal = "Worked!!";
}
})
}
}
});
I have 2 directives, 1 with a 2-way binding to a global function, the other is watching a global variable that the global function is changing. However, somehow when the global function gets called, my watch function is not getting triggered. Any help is greatly appreciated.
Thanks,