【发布时间】:2018-03-23 05:23:12
【问题描述】:
有人可以向我解释为什么使用 Angular 4 模板的这段代码中的工具提示不起作用吗?
<template ngFor let-channel [ngForOf]="channels">
<td>
<em *ngFor="let color of findBallsColor()" class="fa fa-circle {{ color }}" [tooltip]="id"></em>
</td>
</template>
<ng-template #id>
test
</ng-template>
如果我删除<em> 标签内的*ngFor,它可以正常工作(显然只显示一个元素)。我对 Angular 还很陌生,所以我可能对它在这里的实际工作方式有一些了解。
编辑
我发现问题来自 Typescript 函数返回的类型。在上面的代码中,findBallsColor() 返回的列表实际上是一个包含 4 个字段的对象。当我将其更改为仅返回一个字符串时,它可以工作。所以代码看起来是这样的:
HTML:
<template ngFor let-channel [ngForOf]="channels">
<td>
<em *ngFor="let color of findBallsColor()" class="fa fa-circle {{ status.color }}" [tooltip]="id"></em>
</td>
</template>
<ng-template #id>
test
</ng-template>
TS:
findBallsColor():any[] {
return [{"statut":"ERROR","name":"name","otherField":"value","anotherField":"value"}];
}
有人知道这种行为的原因吗?
【问题讨论】:
标签: html angular typescript angular2-template