angularjs - Being wrapped by a directive, how can I access its scope? -
how can access directive's isolate scope in directive's body? dom looks this:
<div ng-app="app"> <directive> <p>boolproperty: {{boolproperty|json}}</p> </directive> </div>
the boolproperty
assigned inside directive's link
function:
angular.module("app", []).directive("directive", function() { return { scope: {}, link: function($scope) { $scope.boolproperty = true; } }; });
the problem is, child <p>
inside directive binds directive's parent scope, not directive's isolated scope. how can overcome this?
you forgot 2 things:
- by default angularjs uses attrubute restriction, in case in directive definition should specify
restrict: "e"
- you should use child scope, not isolated. set
scope: true
inherit parent view scope.
see updated fiddle http://jsfiddle.net/y9g4q/1/.
good luck.
Comments
Post a Comment