javascript - How to read scope properties from parent scope -


i creating simple directive stuck @ beginning. problem unable read property scope in post function. here code:

   <div mod type="{{subnet.isdynamic | type }}"></div>       networkinterfaces.directive('mod', function () {       return {          scope: {             type: '@'         },           link: function (scope, ielement, iattrs, controller) {               console.log(scope.type);               if (scope.type == "static") {                 ielement.css('background', 'blue');             }              if (scope.type == "dynamic") {                 ielement.css('background', 'green');             }          }     } }); 

your scope property wrong , don't need here.

a working plnkr here : http://plnkr.co/edit/ezbzad?p=preview

please refer docs understand scope property inside directive : http://docs.angularjs.org/guide/directive

but if want use :

    app.directive("mod", function(){        return {         scope: {           value: "@value"         },         link: function(scope, element, attrs){           console.log(scope.value);         }       }   }); 

the scope property {} create new isolate scope can't access value. adding value: "@value" scope bind value property note syntax javascript object syntax it's :

value : "@value" , not value = "@value" !!!

oh , last thing : if directive call mod ... in div your attribute is mod not somedirective.


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -