AngularJS directive pass parameters through templateUrl function

自古美人都是妖i 提交于 2019-12-06 17:55:25

I never seen this that way, i always pass an string to the templateUrl property like

...
templateUrl: './foodirective.tmpl.html'
...

You could assign the attrs from your directive element in the linking function:

myApp.directive('fooDirective', function(){
  return{
    restrict: 'E',
    scope: true,
    templateUrl: './foodirective.tmpl.html',
    link: function(scope, elem, attrs){
      // do stuff
      scope.tAttrs = attrs;
    }
  }
})

I've prepared a plunk for you.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!