我正在使用ngcordova contacts Plugin来访问手机通讯录。我有视图模板和控制器。当联系人视图打开时,显示设备的联系人列表。 我使用以下代码访问联系人
contacts.html
<ion-view view-title="Contacts">
<ion-content>
<div class="padding">
<div class="list">
<div class="card" ng-repeat="contact in phoneContacts">
<div class="item item-divider">
{{ contact.name.formatted }}
</div>
<div class="item item-text-wrap">
<p><strong>Phone(s)</strong></p>
<div ng-repeat="number in contact.phoneNumbers">
<p>{{ number.value }}</p>
</div>
<p><strong>Email(s)</strong></p>
<div ng-repeat="email in contact.emails">
<p>{{ email.value }}</p>
</div>
</div>
</div>
</div>
</div>
</ion-content>
controllers.js
.controller('ContactsCtrl', function($scope, ContactsService,$ionicPopup){
$scope.$on('$ionicView.enter', function() {
ContactsService.getAllContacts().then(function (contacts) {
$scope.phoneContacts = contacts;
});
})
})
services.js
.factory('ContactsService',function($q,$cordovaContacts){
return {
getAllContacts:function(){
var deferred = $q.defer();
var options = {};
options.multiple = true;
$cordovaContacts.find(options).then(function(allContacts) {
deferred.resolve(allContacts);
});
return deferred.promise;
}
}
})
此方法在按钮单击操作时工作正常。当open.how解析此
时,不在视图上工作