javascript - Load default data -


i started building app using ionic framework. uses angular.js question should easy answer :)

the challenge: have list of dummy contacts can contactservice. i'd actual contacts of phone. problem is, have wait app load before can access contacts. have wrap inside event listener. code, how can make work (the success function gets array of contacts, checked that)?

document.addeventlistener('deviceready', function() {   statusbar.styledefault();    function onsuccess(contacts) {     contactservice.add(contacts);   };    function onerror(contacterror) {     alert('onerror!');   };    var options = new contactfindoptions();   options.multiple = true;    var fields = ['displayname', 'name'];   navigator.contacts.find(fields, onsuccess, onerror, options); }, false);  angular.module('starter.services', [])  .factory('contactservice', function() {   var contacts = [];    return {     add: function(result) {       contacts = result;     },     all: function() {       return contacts;     },     get: function(contactid) {       return contacts[contactid];     },     count: function() {       return contacts.length;     }   } }); 


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -