0
我想從列表中選擇一個選項。一旦我搜索,應該能夠選擇並顯示在搜索欄上,如this。這是我迄今爲止所做的。如何在找到聯繫人後選擇聯繫人? Ionic 2
我可以搜索聯繫人。我接下來要做的就是從列表中選擇該聯繫人並將其添加到搜索欄(如Gmail和所有)。
模板
<ion-content padding>
<ion-searchbar (ionInput)="findContact($event)" placeholder="Enter display name">
<button ion-button color="light" (click)="findContact($event)" icon-only>
<ion-icon name="add"></ion-icon>
</button>
</ion-searchbar>
<ion-list [hidden]="!search">
<ion-item *ngFor="let item of contactsfound">{{item.displayName}}</ion-item>
</ion-list>
</ion-content>
home.ts
findContact(ev: any) {
let fields: ContactFieldType[] = ['displayName'];
const options = new ContactFindOptions();
options.filter = ev.target.value;
options.multiple = true;
options.hasPhoneNumber = true;
this.contact.find(fields, options).then((contacts) => {
this.contactsfound = contacts;
console.log(JSON.stringify(contacts[0]));
});
if (this.contactsfound.length == 0) {
this.contactsfound.push({
displayName: 'No Contacts found'
});
}
this.search = true;
}
Is this [this example](https:// plnkr .co/edit/9HvbnKbJh4paHRh1yYEB?p =預覽)就像你在找什麼?如果是的話,我會寫出一個更詳細的解釋它的解釋(我知道它是有角度的,它看起來很糟糕,沒有樣式,但語法是相同的) – 0mpurdy
@ 0mpurdy這與我正在尋找的相似。基本上,當我從本地聯繫人列表中搜索並選擇聯繫人姓名時,它應顯示在同一個搜索欄上。 – JBhatt
好,那麼你問的是創建一個過濾列表,綁定到模板或樣式?關於這些問題的相關信息已經在StackOverflow上得到了解答 - 如果您可以將問題分解爲更小的區塊,這將有所幫助:) – 0mpurdy