如何在工厂服务中定义的ng-click中调用该函数,
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>
答案 0 :(得分:4)
应在您的范围内定义该方法,以使其可用于绑定。在您的控制器中,您可以
$scope.setTest=myFactory.setTest;