【问题标题】:Questions reading Ionic 2 documentation阅读 Ionic 2 文档的问题
【发布时间】:2016-12-18 05:01:33
【问题描述】:

我正在尝试学习 Ionic 2,但这已成为一项非常困难的任务

我正在尝试获取设备的所有联系人并在应用中列出。

我去插件页面

https://ionicframework.com/docs/v2/native/contacts/

上面写着find(fields, options)

fieldsContactFieldType[]

但是ContactFieldType 是什么?我在哪里可以找到它?

在学习 Ionic2 的过程中,我曾多次遇到同样的问题。

【问题讨论】:

    标签: ionic-framework ionic2


    【解决方案1】:

    Ionic Native 只是实际的 cordova 插件的包装器。 Check here 由于用法相同,因此您也可以在相应的 cordova repo 中找到完整的文档。

    在你的情况下ContactFieldType is described here

    ContactFieldType 对象是可能的字段类型的枚举,例如“电话号码”或“电子邮件”,可用于控制必须从contacts.find() 方法返回的联系人属性

    【讨论】:

    【解决方案2】:

    使用 Ionic 3 获取设备的所有联系人并在应用中列出他们

    第1步:使用命令提示符安装它

    ionic cordova plugin add cordova-plugin-contacts
    

    第2步:使用命令提示符安装它

    npm install --save @ionic-native/contacts
    

    第三步:打开app.module.ts

    import { Contacts } from '@ionic-native/contacts';
    
    providers: [
        Contacts
      ]
    

    第 4 步:示例打开 home.html

    <ion-list>
      <button ion-item *ngFor="let item of allContacts">
        {{ item._objectInstance.displayName }} 
      </button>  
    </ion-list>
    

    第 5 步:示例打开 home.ts

    import { Contacts } from '@ionic-native/contacts';
    
    @Component({
      selector: 'page-list',
      templateUrl: 'list.html'
    })
    export class ListPage {
    
    allContacts:any;
      constructor(public navCtrl: NavController, public navParams: NavParams, private contacts: Contacts) { 
    
         this.contacts.find(['displayName', 'name', 'phoneNumbers', 'emails'], {filter: "", multiple: true})
        .then(data => {
          this.allContacts = data;
          console.log("data"+JSON.stringify(data));
        });
      }
    }
    

    希望它工作正常参考它:)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-24
      相关资源
      最近更新 更多