I have a component like the one in this picture, and I want to add dynamically html content to the page when the user clicks the add button on the top right. The content that I want to add is a ion-row with some columns which will contain an ion-input which will be editable. Please note that the items that are pre-populated are just text and not ion-input fields. Does anybody know how to add dynamic content to the page?
EDIT: The code of my html component:
<ion-row style="margin-top:5px;background: #272753">
<ion-col col-11 style="color:#59597b;padding-left: 10px;font-size: 12px">
ΤΗΛΕΦΩΝΑ ΕΙΔΟΠΟΙΗΣΗΣ (ΣΕΙΡΑ ΠΡΟΤΕΡΑΙΟΤΗΤΑΣ)
</ion-col>
<ion-col col-1>
<ion-icon float-right name="add" style="color: #ffc200;padding-right: 10px;" (click)="addPhoneNotices()"></ion-icon>
</ion-col>
</ion-row>
<ion-row *ngFor="let phoneNotice of phoneNotices; let i = index;" style="margin-bottom:2px;background: #272753;">
<ion-col col-1>
<img src="../assets/imgs/drag-icon.png" style="height:20px;width:20px;">
</ion-col>
<ion-col col-5 style="color:#ffffff">
{{phoneNotice.name}}
</ion-col>
<ion-col col-5 style="color:#ffffff">
{{phoneNotice.phone}}
</ion-col>
<ion-col col-1>
<ion-icon float-right name="close" style="color:#ffffff; margin-right:10px"></ion-icon>
</ion-col>
</ion-row>
The code of my ts file:
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
@IonicPage()
@Component({
selector: 'page-new-customer',
templateUrl: 'new-customer.html',
})
export class NewCustomerPage {
phoneNotices: Array<{ name: string, phone: string }> = [
{ name: "Ελένη Γεωργίου", phone: "211 45 55 456" },
{ name: "Βαγγέλης Γεωργίου", phone: "687 64 52 354" },
{ name: "Αγγελική Γεωργίου", phone: "687 64 52 354" },
];
constructor(public navCtrl: NavController, public navParams: NavParams) {
}
}
As you can see I use an ngFor loop to show the items. The question now is how to add dynamically a row with ion-input columns. Does anybody know how to add an addPhoneNotice() function which will add to the layout a row with ion-input columns?
Thanks
*ngFordirective. In your html you will have to define a singleion-rowwith this directive to access a variable in your.tsfile. Just share your code so I can adapt it