How would you make an Angular service return a promise? Write a code snippet as an example
Ashuuu Singhhh
To add promise functionality to a service, we inject the “$q” dependency in the service, and then use it like so:angular.factory('testService', function($q) {return {getName: function() {var deferred = $q.defer();//API call here that returns datatestAPI.getName().then(function(name) {deferred.resolve(name);});return deferred.promise;}}; });