0
我是新的Angular 2.我有一種情況,當一個承諾到另一個,我有錯誤消息與http.post工作到以下代碼。我應該如何使用angular 2承諾承諾
。然後
在這裏?
export class KeyValue {
constructor(
private OrganizationId: string,
private OrganizationFriendlyName: string) {
}
}
export interface IComponentData {
title: string;
signInUrl: string;
orgFriendlyName: KeyValue[];
}
@Injectable()
export class Api {
title: string = '<Application Name>';
signInUrl: string = '';
http: Http;
orgFriendlyName: KeyValue[];
postData(): Promise<KeyValue[]> {
var headers = new Headers();
headers.append('Content-Type', 'application/json');
return this.http.post('url', JSON.stringify({}), { headers: headers })
.then(function(res) {
.map(res => res.json());
.subscribe((res: KeyValue[]) => this.orgFriendlyName = res);
});
}
getComponentData(): Promise<IComponentData> {
return this.postData().then(() => {
return new Promise((resolve, reject) => {
resolve({
title: this.title,
signInUrl: this.signInUrl,
orgFriendlyName: this.orgFriendlyName
});
});
});
}
}
我應該如何從POST請求中獲取數據?