上次我尝试以 angular 进行订阅和映射是在 2 年前。 我厌倦了,我尝试了一周或更长时间来映射这些值,而最接近的尝试却让我出错:无法读取未定义的属性“名称”。
这是我的代码:
this.languageService.getAllLanguages().subscribe(languages =>{
this.languages = languages.map((language)=>{
return {
Id:language.Id,
Name: language.Name,
Code: language.Code,
Charset: language.Charset,
Default: language.Default,
Active: language.Active,
SystemId: language.SystemId
}
})
})
this.languageTableElements = [
{
type: 'checkbox'
},
{
type: 'icon',
label: this.languages[0].Name,
icon: 'assets/icons/flag_pl.png'
}
]
答案 0 :(得分:0)
需要在订阅回调中使用 languages
(当它有值时!)
this.languageService.getAllLanguages().subscribe(languages =>{
this.languages = languages.map((language)=>{
return {
Id:language.Id,
Name: language.Name,
Code: language.Code,
Charset: language.Charset,
Default: language.Default,
Active: language.Active,
SystemId: language.SystemId
}
})
this.languageTableElements = [
{
type: 'checkbox'
},
{
type: 'icon',
label: this.languages[0].Name,
icon: 'assets/icons/flag_pl.png'
}
]
})