【发布时间】:2022-01-11 19:31:49
【问题描述】:
我在 ngFor 中有一个 ngIf,我使用索引来检查数组的该索引处的项目是否等于某个值,但是每当我尝试索引任何东西时,它都会给出一个
Module build failed (from ./node_modules/@ngtools/webpack/src/ivy/index.js):
TypeError: Cannot read property 'visit' of undefined
at AstTranslator.translate (<projdirectory>/node_modules\@angular\compiler-cli\src\ngtsc\typecheck\src\expression.js:81:24)
progress.component.ts
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-progress',
templateUrl: './progress.component.html',
styleUrls: ['./progress.component.scss']
})
export class ProgressComponent implements OnInit {
temp = [
"Complete",
"NotAttempted",
"NotAttempted",
"NotAttempted",
"NotAttempted",
"NotAttempted",
"NotAttempted"
]
tasks = [some array of same length]
constructor() { }
ngOnInit(): void {
}
}
progress.component.html
<div class="container">
<div class="wrapper">
<table class = "items">
<thead>
<tr class = "header-row">
<th class = "title-header">Title</th>
<th class = "due-header">Due Date</th>
<th class = "status-header">Status</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let task of tasks; let index = index">
<td>{{ task.title }}</td>
<td>{{ task.dueDate}}</td>
<td>
<div class = "complete" *ngIf="temp[index]==='Complete'">Complete </div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
我不明白 temp 是如何未定义的,因为它是硬编码的? 粗略的 stackblitz 示例:https://stackblitz.com/edit/angular-ivy-xdk4jr?file=package.json 如果需要其他文件,请告诉我。
【问题讨论】:
-
您的错误是无法读取属性“访问”,但您的代码中没有访问
-
是的,我也很困惑为什么会这样说
-
它说明了 AstTranslator.translate,也许你应该检查你的库...你确定错误在你提供的文件中吗?
-
你能为此搭建一个正在运行的堆栈闪电战吗?
-
它适用于 stackblitz,这很奇怪。我想这可能是我的节点模块,但我不确定 AstTranslator 是什么以及做什么
标签: javascript angular