Когда я вызываю фабричный метод AngularJs для привязки списка месяцев со статическим массивом, он работает нормально.Но когда я использую MVC Controller для возврата тех же данных, то $ scope.months не является списком привязок.
Хотя ответ XHR содержит те же данные.Я не знаю в чем проблема.
Ниже приведен фрагмент кода:
HomeController.css
[HttpGet]
public ActionResult GetAllMonths()
{
List<Month> monthList = new JsonRepository<Month>().GetAll();
var output = Json(monthList, JsonRequestBehavior.AllowGet);
return output;
}
AngularJs Factory
(function () {
'use strict'
var app = angular.module("CommonFactory", []);
app.factory("DataFactory", ["$http",DataFactory]);
/*DI For Factory*/
//DataFactory.$inject = ["$http"];
//Factories callBack functions
function DataFactory($http) {
return {
getMonths: function () {
return $http({
method: 'GET',
url: '/Home/GetAllMonths'
}).then(function(response){
return response.data;
});
}
}
}
})();
Контроллер AngularJs
//Modules With Controllers
var app = angular.module("PublicModule", [])
.controller("HomeController", homeController);
//Dependency Injection
homeController.$inject = ["$scope","$http", "DataFactory", "DataService"];
//Functions
function homeController($scope,$http, DataFactory,DataServic) {
$scope.headingText = "Home";
$scope.months = DataFactory.getMonths();
}
![enter image description here](https://i.stack.imgur.com/FcCun.png)