function MyService($q) { return { getSomething() { return $q((resolve, reject) => { if (/* some async task is all good */) { resolve('Success!'); } else { reject('Oops... something went wrong'); } }); } }; } angular .module('app') .service('MyService', MyService);

$q use in angularjs

Similar Code Examples