我想创建一些按顺序执行的代码,如下所示:
@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
返回结果之前执行。