Skip to content

Instantly share code, notes, and snippets.

@janv
Created September 17, 2013 15:12
Show Gist options
  • Save janv/6595705 to your computer and use it in GitHub Desktop.
Save janv/6595705 to your computer and use it in GitHub Desktop.
How to wrap your external callback for AngularJS
mymodule.factory('myWrappedService', function($rootScope){
var originalService; // Must be set from somewhere of course
return {
myAsyncFunction: function(a,b,callback){
return originalService.asyncFunction(a,b,function(){
var args = arguments, self=this;
$rootScope.$apply(function(){
callback.apply(self, arguments);
})
})
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment