gpt4 book ai didi

javascript - 如何在angular 2的ngIf-else中使用表达式

转载 作者:行者123 更新时间:2023-11-30 21:17:04 29 4
gpt4 key购买 nike

这是我的代码

<tr *ngFor="let sample of data; let i = index" [attr.data-index]="i">
<ng-container *ngIf="sample .configuration_type == 1; then thenBlock; else elseBlock"></ng-container>
<ng-template #thenBlock>
<td>{{sample.item_number}}</td>
<td>{{sample.make}}</td>
<td>{{sample.model}}</td>
</ng-template>
<ng-template #elseBlock>
<td>{{sample.serial_number}}</td>
<td>{{sample.capacity}}</td>
<td>{{sample.model}}</td>
</ng-template>
</tr>

错误显示为

无法绑定(bind)到“ngIfThen”,因为它不是“ng-container”的已知属性。1. 如果“ng-container”是一个 Angular 组件并且它有“ngIfThen”输入,那么验证它是这个模块的一部分。2. 如果“ng-container”是 Web 组件,则将“CUSTOM_ELEMENTS_SCHEMA”添加到此组件的“@NgModule.schemas”以抑制此消息。 ("gFor="let sample of data; let i = index"[attr.data-index]="i">

最佳答案

正如错误所说,您不能在同一标签上使用 ngFor 和 ngIf,而是使用 ng-container 执行此操作,

<tr *ngFor="let sample of data; let i = index" [attr.data-index]="i">
<ng-container *ngIf="sample.configuration_type === 1">
<td>{{sample.item_number}}</td>
<td>{{sample.make}}</td>
<td>{{sample.model}}</td>
<td>{{bucket.class}}</td>
<td>{{bucket.capacity}}</td>
</ng-container>
</tr>

关于javascript - 如何在angular 2的ngIf-else中使用表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45566838/

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