I'm working on an app using Ionic and Angular and would like the user to add input fields as they need. All tutorials I see on this topic are using Angular 1.x and I'm using Angular 4.
Here is the HTML:
<ion-content>
<ion-row id="row" ng-repeat= "emailinput of emailinputs">
<ion-col col-3 id="label">
Email
</ion-col>
<ion-col col-8 id="emailcol">
<input type="email" id="email" placeholder="[email protected]" (keyup.enter)="Send($event.target.value)" [(ngModel)]="emailinput">
</ion-col>
</ion-row>
<div padding>
<button (click) = "addnewemail(emailinput)" id="register" ion-button full color="nudgetprim" block>Add</button>
<button (click) = "sendinvite(emailVal)" id="register" ion-button full color="nudgetprim" block>Invite</button>
</div>
</ion-content>
The Typescript for the button is:
addnewemail(emailinput) {
console.log(emailinput)
var emailinputs = [];
var newItem = emailinputs.length+1;
emailinputs.push({'id' : 'row' + newItem, 'name' : 'row' + newItem});
}
*ngFornotng-repeat.ng-repeat is angular 1....*ngFor="let emailinput of emailinputs". also you dont want to declareemailinputs = []everytime the function is called you are emptying everything u added previously...emailinputsshould be in the scope of the page so you can use it with*ngFortype=andid=....and you will want the label to change so you can put {{emailinput.name}} there.