angular - 使用 ComponentFactory angular 6 在表格行中动态添加组件
问题描述
我有一个具有以下 html 的组件
<table>
<thead>
<tr>
<th>
</tr>
</thead>
<tbody>
<ng-container #container class="sample">
</ng-container>
</tbody>
</table
另一个组件有单个 tr(table rows) 即
<tr>
<input class="form-control form-control-text-input" type="text" placeholder="Enter ID" [(ngModel)]="id"/>
</tr>
现在我正在使用这个答案动态添加这个表格行组件 Dynamically ADDING and REMOVING Components in Angular
但是当它在浏览器上呈现时,我得到以下 点击图片
动态组件在 div 中呈现,但我只想在 tbody 中使用 tr。
请帮忙。
更新:我在 stackblitz Stackblitz上创建了一个假人
解决方案
我做了两个更改(下面的屏幕截图)
- 在add-timeseries-row.component.ts文件中,更改选择器:
import { Component } from '@angular/core';
@Component({
selector: 'add-timeseries-row',
templateUrl: './add-timeseries-row.component.html',
styleUrls: ['./add-timeseries-row.component.css']
})
export class AddTimeseriesRowComponent {
id1:string;
id2:string;
id3:string;
}
- 在add-time-series.component.css添加这个
add-timeseries-row {
display: contents;
}
推荐阅读
- uwp - uwp和c#中的反向地理编码
- reactjs - 你如何做一个带有特殊字符的自定义过滤器?
- sql - 如何计算 SQL 数据但也有可能存在或不存在的字段?
- c++ - c++ 编译器优化标志会影响 ABI 兼容性吗
- c# - 网格视图分页。“全部下载”仅下载当前页面
- pandas - 如何锁定始终满足条件的数据帧?
- docker - 将容器作为 Swarm 服务的子节点运行
- unity3d - Unity3d:OnCollisionEnter 问题
- database - 将 API 搜索结果存储在本地数据库中
- google-apps-script - image.asInlineImage().getBlob() 永远挂起