0

I want assign scope variable as calculate variable
{{canMoveNext=((checkList.items | filter:NoMoveNextStatus).length==0)}}
the canMoveNext is a directive isolated scope variable
but I want write it in js code
how can I write it?
I doesnt want to use watch function

bniya dev
  • 29
  • 5

1 Answers1

1

Ways of sharing the variable of directive with controller:

  1. Even though your scope is isolated, you can still make some variables pass it though. You may check the two way binding here. Check out this post on how to do that: link

  2. Otherwise, if possible change the scope from isolated to same scope. Then the variable should be available.

  3. Third way, if you are not doing something dynamic is to store the value in the factory and include the factory as a dependency in the directive and controller. The value needs to be stored in the factory everytime it gets changed. (EDIT: this might not be proper, as you need a watch, which you do not want to use)

  4. Try to avoid this using solution1 or 2, but there is a $rootscope, that is the parent of all scopes, you can include it and store the value there. Its like global variable in js, but you are always inside angularjs. Also, you may directly use that as:

    $scope.$root.someValueThatBehavesLikeGlobal = "value";
    
Community
  • 1
  • 1
Kop4lyf
  • 4,520
  • 1
  • 25
  • 31