【发布时间】:2016-09-01 04:00:14
【问题描述】:
我的最终目标是将一大块数据库分配给基于类的对象。为此,我在.then() 函数的帮助下利用打字稿中的承诺来链接它们。但是我遇到了砖墙。
return(this.httpService.post(someurl, somepayload, someheaders)
.toPromise()
.then(response => response.json())
.then(MyCustomClass.function(MyObject)));
但是,当此代码在获得 response.json() 之前执行 .then(MyCustomClass.function(MyObject)) 时,这会导致我的程序出现问题。
我的问题是,为什么它们会按此顺序发生,有什么办法可以强制它们按顺序执行?
【问题讨论】: