作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这是我的代码
<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/
我是一名优秀的程序员,十分优秀!