我在MVC5中有一个名为Employer的区域,在根目录中有一个名为app的文件夹,其中包含一个名为list的文件夹。在列表文件夹中我创建了js文件,作为服务工厂,我使用了以下代码:
angSalaryApp.factory('listService', ["$http",
function ($http) {
return {
newList: newList
};
function newList() {
return $http.get("Areas/Employer/List/newlist");
}
return {
userLists: userLists
};
function userLists() {
return $http.get("Areas/Employer/List/getlists");
}
}
]);
但是没有调用newlist和userlists操作,并且我的控制器变量未定义。它是我的控制器代码:
angSalaryApp.controller('listController',
function ListController($scope, listService) {
$scope.list = listService.newList;
$scope.userlist = [];
$scope.count = 0;
$scope.submitForm = function () {
};
$scope.loadLists = function () {
$scope.userlist = listService.userLists;
$scope.d = "ffdgdfg";
};
$scope.updateName = function (newtitle) {
$scope.list.Name = newtitle;
};
});
答案 0 :(得分:0)
您需要像这样重组工厂:
angSalaryApp.factory('listService', ["$http",
function ($http) {
return {
newList: newList,
userLists: userLists
};
function newList() {
return $http.get("Areas/Employer/List/newlist");
}
function userLists() {
return $http.get("Areas/Employer/List/getlists");
}
}
]);
...否则userLists将是私有的。
答案 1 :(得分:0)
您是否尝试将路线初始化移至区域注册?
KeyboardListener