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?

click here jsfiddle.

you forgot 2 things:

  1. by default angularjs uses attrubute restriction, in case in directive definition should specify restrict: "e"
  2. 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

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -