Passing variable to Angular Directive

前端 未结 1 556
鱼传尺愫
鱼传尺愫 2020-12-13 18:21

If I have a directive myDir and I call it within ng-repeat like so


相关标签:
1条回答
  • 2020-12-13 19:01

    Try

    <my-dir myindex="$index"></my-dir>
    

    Then

    app.directive('myDir', function () {
      return {
        restrict: 'E',
        scope: {
          myindex: '='
        },
        template:'<div>{{myindex}}</div>',
        link: function(scope, element, attrs){
          scope.myindex = attrs.myindex;
          console.log('test', scope.myindex)
        }
      };
    })
    

    Demo: Plunker

    0 讨论(0)
提交回复
热议问题