У меня есть область с именем Employer в MVC5, а в корне папка с именем 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;
};
});
Вы пытались перенести инициализацию маршрута на регистрацию района?
using System.Web.Mvc;
namespace MyAreaTest
{
public class MyAreaRegistration : AreaRegistration
{
public override string AreaName
{
get { return "MyArea"; }
}
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"Area_default",
"MyArea/{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}
}
Вам необходимо перестроить свою фабрику следующим образом:
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 будут закрытыми.