gpt4 book ai didi

Angular 4 模板错误 : 'anonymous' does not contain such a member

转载 作者:太空狗 更新时间:2023-10-29 17:28:33 28 4
gpt4 key购买 nike

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: Identifier 'name' is not defined. <anonymous> does not contain such a member

起初我以为这与my other issue有关但这是不同的,因为 tabs 的形状没有歧义。模型:该组件清楚地表明 namedata 的每个成员的属性数组,本身是 tabs 的每个成员的属性数组。

这是怎么回事?

最佳答案

尝试在绑定(bind)中添加安全导航运算符 (?),这允许您在路径最初可能有效或可能无效的情况下导航对象路径。

  <div *ngFor="let i of t.data">{{i?.name}}</div>

关于Angular 4 模板错误 : 'anonymous' does not contain such a member,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44916685/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com