Access attrs in AngularJS directive templateUrl -


i have problem don't understand angularjs directives 100% yet. have directive so,

in html:

<div my-directive="hello world"></div> 

in directive js file:

.directive('mydirective', [function ( ) {         return {             restrict: 'a',             priority: 100,             templateurl: 'views/templates/my-directive.html',             link: function (scope, element, attrs) {                 // wish pass attrs.mydirective templateurl             }         };     }]); 

and in templateurl 'views/templates/my-directive.html':

<h1> {{ attrs.mydirective }} </h1> 

obviously work, directive value passed link function not templateurl, how can output value in templateurl? silly question know i'm not sure best way implement is?

you can assigned value scope variable.

  scope.mydirective=attrs.mydirective  app.directive('mydirective', [function ( ) {         return {             restrict: 'a',             priority: 100,             templateurl: 'my-directive.html',             link: function (scope, element, attrs) {               scope.mydirective=attrs.mydirective                 // wish pass attrs.mydirective templateurl             }         };     }]); 

plunker


Comments

Popular posts from this blog

How to group boxplot outliers in gnuplot -

cakephp - simple blog with croogo -