How to write call back functions in angularjs

How to write call back functions in angularjs

You must use promises:
http://markdalgleish.com/2013/06/using-promises-in-angularjs-views/

And maybe, you can search a bit before post a new question.

This is not an Ionic question, but a google search question :smile:

another problem is… what callback functions are questioned?

you can have a function, which accepts function as cb function alias:

function test(param1, params2, callback) {
   // do something
   callback();
}

But if your function is a promise function like:

function test() {
   var q = $q.defer();
   // do something
   if (success) {
       q.resolve();
   } else {
       q.reject();
   }
   return q.promise;
}

you can set callbacks like that:

test().then(function () {
   // success
}, function () {
   // error
});
2 Likes