如何使用连锁电话承诺?

OPV*_*OPV 1 promise typescript angular-promise angular

现在在.then第一节我们所有的另一个承诺http请求:

.then(result => { this.service().then(data => {}); });
Run Code Online (Sandbox Code Playgroud)

这是使用链式承诺的正确方法吗?

Ed.*_*Ed. 5

几乎!你需要在函数中返回promise,如下所示:

.then(result => { return this.service().then(data => {}); });
Run Code Online (Sandbox Code Playgroud)

或者像这样:

.then(result => this.service().then(data => {}));
Run Code Online (Sandbox Code Playgroud)

  • @Daniel 因为 Promise 代表一个值。首先应该将其视为一个值(稍后可用),而不是一些花哨的回调系统。 (2认同)