我正在尝试根据组件字段类型属性创建不同的 html 表内容。我担心的是,当我在操作 html 表时,我无法在我的 tbody 中插入任何额外的 div,因此使用 ng-template 来覆盖这种情况,但我收到了这个异常“没有 NgSwitch 错误的提供者”。
我需要 ngSwitch & ngSwitchCase 不要在 html 的真实元素上。
请建议在这里做什么。
ngSwitch不能在一个<ng-template>元素上,只能在真实元素上,<div>或者你可以使用<ng-container>代替真实元素
这是工作示例:
https://stackblitz.com/edit/angular-ftqywh?file=app/app.component.html
<ng-container [ngSwitch]="type">
<ng-container *ngSwitchCase="'type1'">
<tr *ngFor="let myobj of obj">
<td *ngFor="let data of myobj.arr"></td>
</tr>
</ng-container>
</ng-container>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8804 次 |
| 最近记录: |