【发布时间】:2015-10-22 13:31:35
【问题描述】:
我有一个模块和两个控制器:
var module = angular.module("app", ["agGrid", "ngAnimate", "ngSanitize", "ngDialog"])
module.controller("mainCtrl", ["$scope", "dataService","$timeout","dateFilter","ngDialog", "$http", function ($scope, $http, $timeout, dateFilter, ngDialog, dataService) {
}]);
module.controller("modalCtrl", ["$scope", "ngDialog", "dataService", function ($scope, ngDialog, dataService) {
$scope.printEntity = function () {
console.log(dataService.getEntityArray());
}
}]);
还有一项服务:
module.factory("dataService", function () {
var entityArrayService = [];
return {
setEntityArray: function (entityArray) {
entityArrayService = entityArray;
},
getEntityArray: function () {
return entityArrayService;
}
};
});
我可以从我的 SECOND 控制器内部调用 dataService.setEntityArray(array),但是当我尝试从我的第一个控制器调用它时,它告诉我 dataService.setEntityArray is not a function
【问题讨论】:
标签: javascript html angularjs service controller