明らかではないが、私はRESTサービスを呼び出してデータを保存したいのです、REST呼び出しが成功した(期待される動作)ではないので、私は、このコードが実行されるように期待していた。Angular2:HTTP観測フローは私のコンポーネントで
ERR =>はconsole.log(ERR)& & this.accessLevel ==これは私のRESTサービスからのgetメソッドです
export class CustomerComponent extends SuperChildComponent{
public static url:string='/orderViewCustomer/';
public id;
public allowed: boolean = false;
public accessLevel:AccessLevel =null;
public componentname:string;
public customerData:Customer=null;
constructor(private rest:REST,private authenticationService : AuthorizationService) {
super();
this.componentname=this.constructor.name;
this.accessLevel=this.authenticationService.isUserLoggedIn()?this.authenticationService.componentAccessLevel(this.constructor.name):null;
console.log(this.constructor.name +' has '+this.accessLevel);
if(this.accessLevel==AccessLevel.ENABLED){
this.getData();
}
}
private getData():any{
this.rest.get(CustomerComponent.url,this.id).subscribe(data=> this.storeData(data.json()), err => console.log(err) && this.accessLevel==AccessLevel.DISBLED);
}
private storeData(res:Object):any{
//TODO
//this.customerData =<Customer>res;
this.customerData=<Customer>this.dummy;
}
をAccessLevel.DISBLED:
get(resource: string, id: number, params: URLSearchParams = new URLSearchParams()) {
let headers = this.defaultHeaders;
headers.set("Authorization", this.authdata);
return this
.http
.get(this.getUrl(resource) + '/' + id, params);
// .map((r: Response) => r.json());
}
しかし、エラーブロックは決して実行されず、storeData(dat.json())関数も実行されません。
コールが成功した場合にだけサブスクライバブロックが実行されますか。
ここには何かがありますか?
おかげ
あなたが '成功しない' を定義してもらえをサポートしていますか?エラーコードを返すか、接続できませんか? – Sebastian