【发布时间】:2018-12-19 12:47:33
【问题描述】:
app.component.html:
<div *ngFor="let ivalue of arraytoDispaly;let i = index;">
<input type="text" [value]="ivalue.inputValue" />
<button (click)='GetId(i)'>GetID</button>
app.component.ts:
arraytoDispaly = [
{'inputValue':'abc'},
{'inputValue':'def'},
{'inputValue':'ghi'}];
GetId(val){
console.log()
}
需要在单击按钮时获取输入字段的值,我使用了 ElementRef 和 @ViewChild 但没有获取值。任何人都可以指导我需要做什么,尽管我使用 document.getElementById 通过 id 获得价值,但需要知道 Angular 访问价值的方式,谢谢
【问题讨论】:
标签: angular