I am writing an app using cordova contacts plugin to retrieve all the contacts' display name and phone number, however, I can display all the contacts information through console.log in service's on success function, but I cannot pass all the information to the controller and then display them on the iphone screen's view. How should I suppose to do that. Below are my services.coffee
angular.module 'ionicApp.services', []
.factory "ContactsDB", ->
db = new PouchDB("contacts")
db
.service("ContactsService", [
"$q"
"ContactsDB"
($q, ContactsDB) ->
formatContact = (contact) ->
displayName: contact.name.formatted or contact.name.givenName + " " + contact.name.familyName or "Mystery Person"
emails: contact.emails or []
phones: contact.phoneNumbers or []
photos: contact.photos or []
id: contact.id or "123"
listContacts: ->
options = new ContactFindOptions()
options.filter = ''
options.multiple = true
fields = ["id", "photos", "name", "phoneNumbers"]
navigator.contacts.find(fields, @onSuccess, @onError, options)
onSuccess: (contacts) ->
i = 0
#uuid = device.uuid
while i < contacts.length
#console.log "Display Name = " + contacts[i].name.formatted + " Contact ID = " + contacts[i].id + " Device UUID = " + uuid
ContactsDB.put contacts[i], callback = (err, result) ->
console.log "Successfully insert a contact!" unless err
return
i++
onError: (error) ->
console.log error
])
my controller.coffee
angular.module 'ionicApp.controllers', ['ionicApp.services']
.controller 'NavCtrl', ($scope, $ionicSideMenuDelegate) ->
$scope.showMenu = ->
$ionicSideMenuDelegate.toggleLeft()
.controller "CustomerCtrl", [
"$scope"
"ContactsService"
"ContactsDB"
($scope, ContactsService, ContactsDB) ->
$scope.data = allcontacts: []
$scope.listContacts = ->
ContactsService.listContacts().then ((contact) ->
return
), (failure) ->
console.log "Bummer. Failed to pick a contact"
return
return
]
and my haml
%ion-view(title="客户列表")
%ion-nav-buttons(side="right")
%button.button(ng-click="listContacts()")
Add
%ion-content
.list
%a.item.item-thumbnail-left(ng-repeat="contact in data.allcontacts")
%h2 {{contact.name}}
%h3 {{contact.id}}