-1
私はAngular2 v4.4.0betaを実行しています。私はオブジェクトを返そうとしていて、それは私のAPIからの子です。エンドポイントと呼ばれ、ここではJSONです:子配列がエラーを返すAngular2 jsonオブジェクト
{
"companyId":3,
"name":"Third",
"description":null,
"characters":[{
"characterId":3,
"name":"Third",
"description":null,
"status":null,
"companyId":3,
"userId":null
}]
}
ここでは、これはコンポーネント
の私のGet関数であるCompany.tsimport { Component } from '@angular/core';
import { Character } from './Character';
export class Company {
companyId: number;
name: string;
description: number;
characters: Character[];
}
そしてCharacter.ts
import { Component } from '@angular/core';
export class Character {
characterId: number;
name: string;
description: string;
status: number;
userId: string;
companyId: number;
}
です
getCompany(id: number) {
this.companyService.getCompany(id)
.subscribe(
(data: Company) => this.company = data,
error => this.errorMessage = <any>error);
}
最後にthはサービス機能です
getCompany(id: number): Observable<Company> {
return this.http.get(this.url + "/Get/" + id,
{ headers: this.authService.authJsonHeaders() })
.map((resp: Response) => resp.json() as Company)
.catch(this.handleError);
}
私は項目を別々に取得しますが、両方のモデルは別々に取得しますが、会社内の文字を返すとエラーになります。
クロームデバッガはこのエラーを示している
リソースの読み込みに失敗しました:ネット:: ERR_CONNECTION_RESET
とコンポーネントのログこのエラー
0 - { "isTrustedを":真}
ng?
編集:authHeaderはコール
authJsonHeaders() {
let header = new Headers();
header.append('Content-Type', 'application/json');
header.append('Accept', 'application/json');
header.append('Authorization', 'Bearer ' +
sessionStorage.getItem('bearer_token'));
return header;
}
また、 'this.authService.authJsonHeaders()'は何を返しますか? – anoop
「会社内の文字を返すとエラーになります」これを行う方法を追加できますか? – echonax
私のAPIエンドポイントでは、会社に文字データを添付することもできません。文字データをそのままにしておくと、応答は期待どおりにCompanyモデルにバインドされます。私が文字データを添付すると、私が投稿しているエラーが発生します。 –