Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 通过Ionic应用程序中的ngCordova获取和处理电话联系人_Angularjs_Ionic Framework_Ngcordova - Fatal编程技术网

Angularjs 通过Ionic应用程序中的ngCordova获取和处理电话联系人

Angularjs 通过Ionic应用程序中的ngCordova获取和处理电话联系人,angularjs,ionic-framework,ngcordova,Angularjs,Ionic Framework,Ngcordova,我想得到所有的电话联系方式,并操纵他们发送给服务器。像这样 $scope.contacts = []; $cordovaContacts.find({ filter: '', fields: ['displayName','phoneNumbers'] }).then(function (allContacts) { angular.forEach(allContacts, function (contact, index) { $sco

我想得到所有的电话联系方式,并操纵他们发送给服务器。像这样

$scope.contacts = [];

$cordovaContacts.find({
      filter: '', 
      fields: ['displayName','phoneNumbers']
}).then(function (allContacts) {

    angular.forEach(allContacts, function (contact, index) {
          $scope.contacts.push({
              "first_name": contact.name.givenName,
              "last_name": contact.name.familyName,
              "phone_number": contact.phoneNumbers[0].value
          });
    });
});
HTML

<p style="white-space: pre;">{{contacts | json: 3}}</p>

{{{contacts}json:3}


但是
angular.forEach
不工作,没有错误,有什么问题吗?

最后解决问题::

$cordovaContacts.find({
      filter: '', 
      fields: ['displayName', 'name', 'phoneNumbers']
}).then(function (allContacts) {

    var contacts = [];

    angular.forEach(allContacts, function (contact, index) {

       if (contact.phoneNumbers != null && 
           contact.phoneNumbers[0].type == 'mobile' &&
           contact.name != null) {

           // if user have firstName and lastName
           if (contact.name.givenName && contact.name.familyName) {

             contacts.push({
                "first_name": contact.name.givenName,
                "last_name": contact.name.familyName,
                "phone_number": contact.phoneNumbers[0].value
             });

           } else {

             contacts.push({
                "first_name": contact.name.givenName ? contact.name.givenName : '',
                "last_name": contact.name.familyName ? contact.name.familyName : '',
                "phone_number": contact.phoneNumbers[0].value
             });

           }

        }

    });    

});

您确定
allContacts
不为空吗?是的,因为当我使用
$scope.contacts=allContacts
时,一切都正常。