私はこのAngular Controllerを持っています:
(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 に送り返し、organizationController.js のこの行に到達します。Chrome デバッガーで確認できました。
dataService.GetOrganizationById(id).then(function (result)
ただし、次の行ではデータが失われ、システムは 204 エラー コード: データなしを返します。
vm.organization = result.data;
コントローラーが変数「結果」で送信されるデータを受け入れない理由は何ですか?
私は Visual Studio 2015 EF と C# バックエンドで作業しています。しかし、情報を取得し、Postman でも表示されるため、問題はフロントエンドにあるだけです