Hi,
I have a question on isolate scope in directive. Basically I want to watch
a variable in controller. When it changes after 5 seconds I want to console
log the change.
My Controller:
app.controller("TestCtrl", ['$scope', '$timeout', function($scope, $timeout)
{
$scope.variable = true;
$timeout(function(){
$scope.variable = false;
}, 5000);
}]);
My Directive:
app.directive("watchMan", function() {
return {
restrict: 'A',
scope: {
monitor: "=" //works
//monitor: "@" does not work
},
link: function(scope, elem, attr){
scope.$watch('monitor', function(newVal, oldVal){
console.log('changed from '+newVal + ' to ' + oldVal);
});
}
};
});
Usage in HMTL:
<div ng-app="TestApp">
<div ng-controller="TestCtrl">
<div watch-man monitor="variable"></div>
</div>
</div>
>From what I learnt about directives using isolated scope, the '@' is used
for reading a value from controller, but this does not work but thats what
I'm doing here.
Using bi-directional "=" works. Why is this the case?
I have a working example
here: https://jsbin.com/fogifaloro/1/edit?html,js,console
Thanks.
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.