angularjs directive call function specified in attribute and pass an argument to it

后端 未结 7 775
难免孤独
难免孤独 2020-12-22 17:11

I want to create a directive that links to an attribute. The attribute specifies the function that should be called on the scope. But I also want to pass an argument to the

7条回答
  •  执笔经年
    2020-12-22 17:55

    This should work.

    app.directive("myMethod",function($parse) { restrict:'A', scope: {theMethodToBeCalled: "="} link:function(scope,element,attrs) { $(element).on('theEvent',function( e, rowid ) { id = // some function called to determine id based on rowid scope.theMethodToBeCalled(id); } } } app.controller("myController",function($scope) { $scope.theMethodToBeCalled = function(id) { alert(id); }; }

提交回复
热议问题