angular中的Issue witch async(列出Web Api中的元素)
以下是代码片段:angular中的Issue witch async(列出Web Api中的元素),angular,typescript,asynchronous,Angular,Typescript,Asynchronous,以下是代码片段: this.languages = await this.languageService.getAllLanguages().toPromise() this.languages.forEach(async (value, index) => { console.log(value.name) this.originLanguageOption.setDropdownOption ( value.name,
this.languages = await this.languageService.getAllLanguages().toPromise()
this.languages.forEach(async (value, index) => {
console.log(value.name)
this.originLanguageOption.setDropdownOption (
value.name,
index
)
this.originLanguageOptions.push(
this.originLanguageOption
)
})
this.originLanguageDropdown.setDropdown(
'Origin language',
'Choose Language',
this.originLanguageOptions
)
问题:
控制台日志工作正常,它只是列出DB中的所有元素,但当我尝试将数据分配给“this.originLanguageOptions”时,它会覆盖列表中以前的所有元素。该数组看起来像:
第一圈:
- 英式
- 德文
- 德文
- 法国
- 法国
- 法国
- 英式
- 德文
- 法国