angular - Angular2 get values of dynamically created inputs -
i have input created dynamically list column
, need values of inputs when method occurs( imagine getallvalues()
)
<div *ngfor="let cell of column; let = index;"> <!-- material design input--> <md-input type="{{cell.type}}" value="{{getinputvalue(cell)}}" [placeholder]="cell.label"> </md-input> </div>
which angular2 way of getting values of generated inputs?
the easiest way using ngform
<form #myform="ngform"> <div *ngfor="let cell of column; let = index;"> <md-input [type]="cell.type" [name]="cell.name" <!-- note 'name' has set --> [ngmodel]="cell.value" [placeholder]="cell.label"></md-input> </div> <a (click)="getallvalues(myform)">print values</a> </form>
then have access myform.form.value object in getallvalues() function. plnkr: https://plnkr.co/edit/84mzcnjlimmvszpq3xmm?p=preview
Comments
Post a Comment