0

I have in my directive the controller and link in the following way:

myapp.directive('MyDirective', function(){
    return{
        restrict: 'A',
        transclude: true,
        scope: {
          ....
        },
        controller: function($scope) {
           $scope.variable = true;

        },
        templateUrl:  './app/templates/template.html',
        link: function(scope, element, attrs){
            scope.$watch('variable ', function(){
            console.log("variable : " + scope.variable )
          });
       }
       .....

I am not able to see the scope.variable in the block link. How I can resolve it?

mccainz
  • 3,478
  • 5
  • 35
  • 45
user880386
  • 2,737
  • 7
  • 33
  • 41
  • Look again at how to use [$watch](https://docs.angularjs.org/api/ng/type/$rootScope.Scope#$watch) – Razvan B. Jun 26 '15 at 15:18
  • What do you mean by the "block link"? Please include the relevant HTML as well. If you are trying to watch a variable not in the directive's isolate scope, you are probably looking for something like `scope.$parent.$watch()` – ryanyuyu Jun 26 '15 at 15:27
  • I defined the $scope.variable into the directives' controller .I would like to use it in the scope.watch.. I can try to use scope.$parent.$watch – user880386 Jun 26 '15 at 15:56

0 Answers0