【发布时间】:2017-12-08 13:25:01
【问题描述】:
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}>
}>=[];
component.html
<section *ngFor="let t of tabs">
...
<div *ngFor="let i of t.data">{{i.name}}</div>
^^^^^^
</section>
编译器错误
Angular:未定义标识符“名称”。
<anonymous>不包含这样的成员
起初我以为这与my other issue 相关联,但这次有所不同,因为tabs 模型的形状没有歧义:组件清楚地表明name 是@ 的每个成员的属性987654329@数组,本身就是tabs数组每个成员的属性。
这里发生了什么?
【问题讨论】:
-
在哪里将数据分配到选项卡中?请在这里发帖。 bcz 我测试你的代码工作正常
-
@ShaileshLadumor 即使我从不分配任何东西(例如:如果我删除我的
ngOnInit()),也会引发此错误;所以错误不是由数据如何分配给tabs引起的。请记住,错误发生在我的代码编辑器中,而不是在运行时,因此它与从服务器返回的数据没有任何关系 -
我测试了您的代码,但工作正常。在 onNgInit() 中分配 dayta 选项卡并将其打印到 tamplate/.
-
您在使用插件语言服务吗?你用的是哪个编辑器?
-
我在使用带有 VS Code 的 Angular 语言服务扩展时遇到了同样的错误。我认为这是 Angular 语言服务中的一个错误,但我还没有找到任何解决方法。
标签: angular typescript angular-template