【发布时间】:2019-01-17 17:08:01
【问题描述】:
我在使用 .net 核心 SPA 应用程序时遇到问题。 - 结果由 API 调用传回 - SPA 不处理结果。
这里是相关代码:
SPA ts:
class TestLibraryItem {
private _apiPath: string;
private _http: HttpClient;
public name: string;
public testResults: TestResult;
constructor(name: string, apiPath: string, http: HttpClient) {
this.name = name;
this._apiPath = apiPath;
this._http = http;
}
RunTests() {
this._http.get<TestResult>(this._apiPath)
.subscribe(result => {
this.testResults = result;
console.log(this.testResults);
console.log(this.testResults.CheckName);
});
}
}
class TestResult {
CheckName: string;
Checks: CheckResult[];
}
class CheckResult {
Test: string;
Pass: boolean;
}
以及触发 RunTests() 时的控制台结果:
{"CheckName":"Check One","Checks":[{"Test":"Test one","Pass":true},{"Test":"Test two","Pass":true}]}
undefined
据我所知,我从 API 中获取了有效的 json(由 console.log 吐出表示,但它实际上并没有构建导致未定义的对象。
【问题讨论】:
标签: json angular asp.net-core-webapi