【发布时间】:2018-05-22 15:06:23
【问题描述】:
我尝试使用参数运行 *ngFor。
我想按参数输出消息,例如 {{data.lang}}
谢谢。
我的代码如下:
-=app.component.html=-
{{lang}}
<div>
<ul>
<li *ngFor = "let data of datas">{{data.en}}</li>
</ul>
</div>
-=app.component.ts=-
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'app';
lang: string = 'en';
datas: any = [
{
"ru": "время деньги.",
"en": "time is money",
"fr": null,
"it": "il tempo è denaro",
"de": "Zeit Geld",
"es": "el tiempo es dinero",
"pt": "tempo é dinheiro",
"pl": "czas i pieniądze"
}
]
}
【问题讨论】:
-
您的问题到底是什么?这段代码不适合你吗?
-
你有什么错误吗?
-
这是一个合理的问题。他在“数据”对象上没有“语言”属性,因此表达式值将是未定义的,没有错误,呈现空字符串。
-
其打印
{{data.en}} in a loop