我有这个角度控制器:
(function () {
"use strict";
angular.module('appContacts')
.controller('organizationsController', function organizationsController(dataService, $stateParams) {
var vm = this;
vm.visible = false;
var id = $stateParams.Id;
activate();
function activate() {
dataService.GetOrganizationById(id).then(function (result) {
vm.organization = result.data;
}, function () {
vm.errorMessage = "Failed to load" + Error;
});
}
});
})();
这是我的dataService文件:
(function () {
angular.module('appContacts')
.factory('dataService', ['$http', dataService]);
function dataService($http) {
return {
getAllOrganizations: getAllOrganizations,
GetOrganizationById: GetOrganizationById,
};
function getAllOrganizations() {
return $http({
method: 'GET',
url: 'api/organizations'
});
}
function GetOrganizationById(id) {
return $http({
method: 'GET',
url: '/api/organizations/{id}'
});
}
})();
此dataService.js调用存储库中的GetOrganizationById方法,如下所示:
...
public Organization GetOrganizationById(Guid Id)
{
return _context.Organizations
.Include(o => o.Contacts)
.ThenInclude(c => c.Phone.main == true)
.Where(o => o.Id == Id)
.FirstOrDefault();
}
...
存储库成功获取信息,发送回dataService.js并在organizationsController.js中到达此行。我可以在Chrome调试器中看到:
dataService.GetOrganizationById(id).then(function (result)
但是在下一行中,数据丢失,系统返回204错误代码:无数据。
vm.organization = result.data;
任何想法为什么Controller不接受变量中发送的数据"结果"?
我在Visual Studio 2015 EF和C#后端工作。但问题只是在前端,因为我得到了信息,我也看到了Postman