如何獲取某個特定控制器的$scope
變量?如何在模塊中調用控制器的方法(AngularJS)
myApp.factory('Comment', ['$http', function ($http) {
var comment = {};
comment.add = function (shortName, taskNum, message) {
// how to call controller's method
// the following line dosen't work
myApp.ListPanelController.showTaskDetail(shortName, taskNum);
}
return comment;
}
myApp.controller('ListPanelController', ['$scope', 'Comment',
function ($scope, Comment) {
$scope.showTaskDetail = function (shortName, taskNum) {
Tasks.get(shortName, taskNum).success(function (data) {
// do something
});
}
}]
);
您需要解釋您的方案。服務是共享代碼\功能和控制器是視圖特定的。應該沒有理由從服務調用控制器功能。 – Chandermani