【发布时间】:2017-12-26 09:32:27
【问题描述】:
我有一个配置加载函数,它从 json 文件加载一些数据并用它解决一个承诺。
当我调用加载函数时,我想知道处理错误的更好方法是什么。据我了解,可以有两种选择。
public config: any = this.configProvider.load()
.then(data => this)
.then(error => console.error(error));
对
public config: any = this.configProvider.load()
.then(data => this)
.catch(function(err){
console.log(err);
}
【问题讨论】:
-
在承诺链的末尾使用 catch。
-
my answer 有帮助吗?
标签: javascript angular typescript promise es6-promise