ngOnChanges
はasync
をサポートしていないため、この問題が発生しましたが、async
メソッドの処理方法はわかりません。ngOnChangesで非同期を処理する方法
これを行うにはどうすればよいですか?
async
をngOnChanges
に適用すると機能しません。戻り値はPromise
です。
@Component({
moduleId: module.id,
selector: 'search',
templateUrl: 'search.template.html'
})
export class Search implments OnChanges {
async queryArray(data: string): Promise<T> {
//sample scripts.
return ....;
}
ngOnChanges(changes: SimpleChanges) {
let query: string = "red";
let result: string[] = [];
await this.queryArray(query).then(resp => result = resp);
}
}
ngOnChangesスコープの代わりにcomponentsスコープにレスポンスを保存できますか? this.queryArrray(query).then(resp => this.result = resp);これを待つ。 – LLai