How to write call back functions in angularjs


#1

How to write call back functions in angularjs


#2

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.


#3

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


#4

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
});