Angular Directive Different Template

前端 未结 6 1708
渐次进展
渐次进展 2020-12-07 20:51

I have a directive myDirective with variable type. If I run I want the directive to use templateUrl: x-template.html. If I do <

6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-07 21:43

    Ok, this might help someone here :-)

    To inject your custom attr into your link or controller function use the following.

    I'm at work right now but will post a fiddle later if I get a chance :-)

    .directive('yourDirective', function() {
      return {
        restrict: 'EA',
        template: '
    ', // or use templateUrl with/without function scope: { myAttibute: '@myAttr' // adds myAttribute to the scope }, link: function(scope) { console.log(scope.myAttibute); } } }

    // HTML ""

    // Console will output "foo"

提交回复
热议问题