I have some code that I am working on, that allows a user to pick a contact, I want the code to be able to populate an array,
as that then populates the Html template with NgFor
However, I am battling to make the function change data in the array dynamically could anyone help me or at least point me into a direction.
here is the relevant code html file
<ion-list>
<ion-grid>
<ion-row>
<ion-col>
<ion-item-group (click) = "pickContact()" *ngFor="let contacts of mContacts">
<ion-card>
<ion-item lines = "none">
<ion-label class="ion-text-wrap">Name: {{contacts.name}}</ion-label>
</ion-item>
<ion-item lines = "none" >
<ion-label class="ion-text-wrap">Number: {{contacts.number}}</ion-label>
</ion-item>
</ion-card>
</ion-item-group>
</ion-col>
</ion-row>
</ion-grid>
</ion-list>
I want the function pickContact to be called when the card is selected and then populate the corrosponding element in the array. ts file
export class ContactComponentComponent implements OnInit {
constructor(private contacts: Contacts) { }
mContacts = [
{
name: [''],
number: ['']
},
{
name : ['Carl'],
number: ['065 623 4567']
}
];
ngOnInit() {}
//currently thows an error:
//Property 'name' does not exist on type '{ name: string[]; number: string[]; }[]'.
//Property 'number' does not exist on type '{ name: string[]; number: string[]; }[]'
pickContact() {
this.contacts.pickContact().then((contact) => {
this.mContacts.name = contact.name.givenName;
this.mContacts.number = contact.phoneNumbers[0].value;
});
}
}