Bee*_*ice 8 typescript angular-template angular
Angular 4 写的 Typescript 2.3.4
component.ts
/**
* Info that drives the tabs in the template. Array is filled
* in ngOnInit() once data is received from the server
*/
public tabs:Array<{
title:string,
description:string,
data:Array<{name:string}>
}>=[];
Run Code Online (Sandbox Code Playgroud)
component.html
<section *ngFor="let t of tabs">
...
<div *ngFor="let i of t.data">{{i.name}}</div>
^^^^^^
</section>
Run Code Online (Sandbox Code Playgroud)
编译错误
Angular:未定义标识符'name'.
<anonymous>不包含这样的成员
起初我还以为这是链接到我的其他问题,但因为在形状没有歧义,这是不同的tabs模式:组件清楚地表明,name在各成员的属性data阵列本身的每个成员的属性tabs阵列.
这里发生了什么?
尝试在绑定中添加安全导航运算符 (?),这允许您在路径最初可能有效或无效的情况下导航对象路径。
<div *ngFor="let i of t.data">{{i?.name}}</div>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3251 次 |
| 最近记录: |