ngFor - 无法绑定到“testid”,因为它不是“input”的已知属性。如何将 id 与字符串连接起来?

3gw*_*ain 8 angular angular-template-variable angular8 angular-testing-library

我正在尝试用我的 ID 添加index值。但出现错误:

Can't bind to 'testid' since it isn't a known property of 'input'.
Run Code Online (Sandbox Code Playgroud)

这是我的模板:

<td *ngFor="let col of columns; let i = index"  [ngClass]="col.class" data-testid="form-create-td-{{i}}">
Run Code Online (Sandbox Code Playgroud)

我的代码有什么问题吗?有人帮助我吗?

Ris*_*ise 18

我认为你需要属性绑定。因此,请尝试替换以下 testid 数据属性。

<td ... [attr.data-testid]="'form-create-td-' + i">
Run Code Online (Sandbox Code Playgroud)

对于将 id 属性与字符串连接起来,您正在做正确的事情。