0

私は次の要素を持っています、

<button test-directive>value</button>

を使用できることはわかっていng-click directiveますが、コントローラーから関数を呼び出す必要があります。ユーザーがクリックすると、例で呼び出されるディレクティブを起動したいtest-directive

testModule.directive('testDirective', function(){
return {
    restrict: 'A',
    link: function(scope, element, attrs) {      }
  }
})

このディレクティブでng-clickを実装するにはどうすればよいですか?

ありがとうございました

4

2 に答える 2

2

私があなたの考えを理解したかどうかはわかりません。

これがプランカーです

directive('testDirective', function(){
return {
    restrict: 'A',
    replace:true,
    template:'<button ng-click="fire()">test</button>',
    controller:function($scope, $element, $attrs){
        $scope.fire = function (){
            console.log("fire !");
        };
    }
  };
});
于 2012-11-01T14:46:17.540 に答える
0

マキシザムの答えは正しいですが

<span test-directive>value</span>代わりに使用できますが 、<button test-directive>value</button>ボタンは引き続き表示されます。

プランカー

于 2015-02-06T16:22:19.333 に答える