问题
How can I call the function in ng-click which is defined inside a factory service,
app.factory('MyFactory', [function () {
return {
setTest: function(test) {
alert(test);
}
};
}]);
app.controller('TestCtrl', ['$scope','MyFactory', function ($scope, MyFactory) {
}]);
<li><a href="#" ng-click="setTest('PHP')">PHP</a></li>
<li><a href="#" ng-click="setTest('Javascript')">Javascript</a></li>
回答1:
The method should be defined on your scope for it to be usable in bindings. In your controller you can
$scope.setTest=myFactory.setTest;
来源:https://stackoverflow.com/questions/22318760/how-to-call-function-in-ng-click-which-is-defined-in-factory-service