函数中的包装承诺仅在承诺完成时返回

时间:2017-03-28 12:36:53

标签: angular promise angular-promise

我想创建一些按顺序执行的代码,如下所示:

@Input() feedType;
constructor(private _newsService: NewsService) { }
//call getNews with selected `feedType`
ngOnInit() {
    this.getNews(this.feedType);
}

运行此代码时,最终console.log('Called before the function containing a promise'); var result = getSomeData(); console.log('Called after getSomeData() has completed fully'); getSomeData() { var stuff = <do something here>; return dbGetDocument(stuff).then((result)=>{ return result; }); } dbGetDocument() is an existing library function (written by someone else) that returns a promise. 会在console.log返回结果之前执行。

0 个答案:

没有答案