javascript - Directive talks to controller but cannot call functions residing in controller -
i have directive needs call functions main controller everytime try reference function inside directive nothing happens because it's undefined. when access value instance $scope.someprop desired response not when call function.
anyone else who's faced issue? suggestions?
few things:
- your controller exposes startchange function on scope, need call on scope, i.e. 'scope.startchange()' within directive , not 'startchange()'
- your confirmation directive uses isolate scope great if know youre doing, in essence cutting off parents scope on trying call function
you got 3 options in case
- use scope $emit/$broadcast share state
- use isolate scope , '&' syntax execute expression in context of parent scope -- example http://plnkr.co/edit/8uedpos6ie5qtfc8e08h?p=preview
- not use isolate scope , execute startchange function on scope of directive same scope of controller -- example: http://plnkr.co/edit/h1t2qnol7wgng0eprlmc?p=preview
Comments
Post a Comment