简体   繁体   English

Nativescript 如何在像 document.write() 这样的打字稿中编写 HTML

[英]Nativescript how to write HTML in typescript like document.write()

basically I want to generate a specific number of labels at different row/col positions based on user input but I cannot find anywhere that tells how to write to the .component.html document from the .component.ts document.基本上我想根据用户输入在不同的行/列位置生成特定数量的标签,但我找不到任何告诉如何从 .component.ts 文档写入 .component.html 文档的地方。 I basically want to use something like document.write() but for nativescript.我基本上想使用类似 document.write() 但对于 nativescript 的东西。

Use interpolation (denoted by {{...}} ) to insert data from component in template:使用插值(由{{...}} )从模板中的组件插入数据:

Component:成分:

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;
    }
  }
}

Template (HTML):模板(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)">

Working example: Stackblitz工作示例: Stackblitz

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM