I am facing a challenge with an element that has both a controller and a directive featuring an isolate scope:
scope: {
dirVar: '= '
}
My objective is to execute specific parts of the directive only when a certain variable is true. I am trying to set this variable in the controller and pass it into the directive through an attribute.
The issue arises when I attempt something like
<div ng-controller="MyCtrl" my-directive active="ctrlVar"></div>
and then try to access active
in the directive using scope.active
, but it always returns undefined.
You can see an example here: http://jsfiddle.net/u3t2u/1/
Could you please provide an explanation as to why this is happening and suggest the correct method to address this issue? I suspect that the problem lies with having both the controller and directive on the same element and would like to find a workaround.
Alternatively, I could consider removing the directive's isolate scope and have it evaluate an attribute passed to it, although I am currently encountering errors with $parse
.