[英]Nativescript how to write HTML in typescript like document.write()
基本上我想根据用户输入在不同的行/列位置生成特定数量的标签,但我找不到任何告诉如何从 .component.ts 文档写入 .component.html 文档的地方。 我基本上想使用类似 document.write() 但对于 nativescript 的东西。
使用插值(由{{...}}
)从模板中的组件插入数据:
成分:
export class AppComponent {
name = 'Angular';
labels = [
{
id: '1',
name: '',
},
{
id: '2',
name: '',
},
{
id: '3',
name: '',
},
];
public onKey(event: any) {
for (const label of this.labels) {
label.name = event.target.value;
}
}
}
模板(HTML):
<div class="divTable">
<div class="divTableBody">
<ng-container *ngFor="let label of labels">
<div class="divTableRow">
<div class="divTableCell">{{ label.id }}</div>
<div class="divTableCell">{{ label.name }}</div>
</div>
</ng-container>
</div>
</div>
<p>Type here:</p>
<input (keyup)="onKey($event)">
工作示例: Stackblitz
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.