ng-click在指令

时间:2017-03-27 06:44:37

标签: angularjs

angular ng-click在这样的指令中不起作用

 <repeat-some-thing data-ng-click="doSomeThing()" collection='packages'/> </lr-repeattemp>
angular.module('app').directive:
  directive('repeatSomeThing', function() {
    return {
      restrict: "EA",
      replace: true,
      scope: {
        collection: '=',
        doSomeThing: '&ngClick'
      },
      template: "<member ng-repeat='member in collection' member='member'></member>"

    }
  })

  .directive('member', function($compile) {
      return {
        restrict: "E",
        priority: 800,
        replace: true,
        scope: {
          member: '=',
          doSomeThing: '&ngClick'
        },
        template: '<li ng-click="doSomeThing()"><a><i class="{{member.icon}}"></i><span class="title">{{member.title}}</span></span></a></li>',
        link: function(scope, element, attrs) {
          element.children('a').attr('ui-sref', scope.member.sref);
          $compile(element.contents())(scope);
        }
      })
  })
angular.module('app').controller(myctrl, function($scope) {
  $scope.doSomeThing = function() {
    alert(123)
  };
})
<repeat-some-thing collection='packages' /> </repeat-some-thing>

ng-click和功能doSomeThing()在我的代码中不起作用

0 个答案:

没有答案