Reputation: 1364
I have created Angular2 code like this to get the data on button click
<div class="field-panel">
<div>
<span>
<input #newData [(ngModel)]="data.id" type="text" >
<select #newCategory [(ngModel)]="i.index" class="input-bars">
<option *ngFor="let data of field" [value]="data.value">{{data.value}}</option>
</select>
</span>
<button class="btn btn-success (click)="addData(newData.value, newCategory.value)">ADD</button>
</div>
</div>
addData(value, dropValue){
this.Data[index] = value;
}
But when the button is clicked the data on the input field is getting lost in ui. How to keep it when the button is clicked and display on the ui as well??
Upvotes: 0
Views: 177
Reputation: 8335
I'll hazard a guess that you're working in a form, so add type="button"
to the button <button class="btn btn-success" (click)="addData(newData.value)">ADD</button>
. That should prevent it from thinking the form is submitting and clearing the data.
Upvotes: 1