AngularJS my custom directive can't access attributes yet it appears other custom directives can -


i have following template custom directive.

    .directive('mydirective', ['$controller',function($controller) {       return {             templateurl: 'client/test.ng.html',             scope: true,             controller: ['$scope','$attrs',function($scope,$attrs){               console.log($attrs)           }],           transclude: true,        }     }]) 

this directive being called follows

    <my-directive view="{{view}}"></my-directive>     <ion-tab ng-if="platform != 'android'" title="{{label}}"  icon-off="{{off}}" icon-on="{{on}}" href="#/tab/{{view}}">              <my-directive view="{{view}}"></my-directive>     </ion-tab>      <ion-tab ng-if="platform == 'android'" title="{{label}}" class="tab-item" href="#/tab/{{view}}">             <my-directive view="{{view}}"></my-directive>     </ion-tab> 

$attrs.view {{view}}, uninterpolated. <ion-tab> interpolates expression variable value, displaying right data.

this confusing me. i've put my-directive both inside , outside ion-tab directive in case there kind of scoping issue.

what key accessing value of expression , using value in turn call directive?


background:

the reason i'm going through because

<ion-nav-view name="tab-{{view}}"></ion-nav-view> doesn't work. it, my-directive doesn't seem able value ```view`` raw uninterpreted request it. i'm attempting value , call directive directly.

i seem able value want $scope.$parent.view yet mysteriously setting $scope.view = $scope.$parent.view , setting {{view}} in child template doesnt work either!?


more insight, console.log($attrs) gives:

  $…t.attributes {$attr: object, $$element: jquery.fn.init[1], view: "{{view}}", class: "pane tab-content", navview: "active"} 

yet when expanded have

   $$element: jquery.fn.init[1]      $$observers: object      $attr: object      class: "pane tab-content"      navview: "active"      view: "dash"      __proto__: object 

any appreciated, thanks.

use link function attributes values.

.directive('mydirective', ['$controller',function($controller) {   return {         templateurl: 'client/test.ng.html',         scope: true,         transclude: true,         link: function(scope,element,attrs){           console.log(attrs);         }    } }]) 

Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

php - Find a regex to take part of Email -