【发布时间】:2018-06-27 09:10:40
【问题描述】:
我在 referencesPromise 和 contactTypesPromise $onInit() 中的两个变量中分配了两个对 Web 服务的调用(如果需要,我可以为此创建一个新方法)
$onInit() {
const referencesPromise = this.ReferenceService.getMultipleReferences(this.AgentReferences)
const contactTypesPromise = this.ContactService.getContactTypes()
Promise.all([referencesPromise, contactTypesPromise]).then((responses) => {
this.references = responses[0]
this.contactTypes = responses[1]
const stateParams = this.$state.params
return this.setContactSteps()
})
}
他对 async-await 的替代方案是什么?
【问题讨论】:
-
你想让 onInit 异步/等待吗?
-
@zabusa 是的,或者为此创建一个新方法
-
你可以在onInit()中调用异步函数
-
@zabusa 如果我将逻辑移到新方法上?
-
(对于 AngularJS)你应该使用
$q.all()而不是Promise.all()
标签: javascript angularjs async-await ecmascript-2017