I am working on an AngularJs application and I have a confusing issue here when I am trying to watch on controller scope property within link function of a directive
Here is minimal example of the issue
HTML
<div fc-loading="filterBox"></div>
controller
angular.module('myApp').controller('myctrl', function ($scope) {
$scope.filterBox = false;
setInterval(function () {
$scope.filterBox = !$scope.filterBox;
},2000)
}
Directive
angular.module('myApp').directive('fcLoading', function () {
return{
scope:{
fcLoading:'='
},
link: function (scope,ele,attrs) {
scope.$watch(scope[attrs.fcLoading],function(newValue, oldValue){
console.log(newValue)
}
}
Thanks in advance!
$scope.filterBox
I am using the attributes to just isolate the scope - Peter Wilson