小编Meh*_*t S的帖子

Angular 5 [对象 HTMLDivElement]

当我单击按钮时,我将“copyRow”元素发送到“copyItem”方法。我将“copyItem”元素与“Typescript”文件中的“item”变量进行均衡。

当我想显示“[object htmldivelement]”时,这个“html 文件中的项目”变量将作为输出。

创建.component.html

<div class="questions">
    <div class="form-group copy-row" #copyRow>
       <label>Question</label>
       <input type="text" class="form-control" placeholder="Question title">
    </div>
    {{ item }}
</div>
<button type="button" class="btn btn-primary" (click)="copyItem(copyRow)">Add</button>
Run Code Online (Sandbox Code Playgroud)

创建组件.ts

  item;

  constructor() { }

  ngOnInit() {
  }

  copyItem(row) {
    this.item = row;
  }
Run Code Online (Sandbox Code Playgroud)

编辑

我的目标是做一个调查项目。当我单击“添加”按钮时,相同的“#copyRow”元素将显示在 {{ item }} 部分中。但是,我得到了类似于第二个链接的输出。

1: http: //prntscr.com/j1ncp1 2: http: //prntscr.com/j1nd19

html typescript angular angular5

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

angular ×1

angular5 ×1

html ×1

typescript ×1