How would you make an angularjs service return a promise? Write a code snippet as an example
Answer / Bhup Singh
[n function MyService($q) {n this.myMethod = function() {n var deferred = $q.defer();n // Some asynchronous operation heren deferred.resolve('Result');n return deferred.promise;n }n }n]nInject MyService into your controller and call `myService.myMethod().then(function(result) {...})` to handle the promise.
| Is This Answer Correct ? | 0 Yes | 0 No |
Explain angular js boot process.
Explain the concept of scope. How does scope inheritance work in angularjs?
How to set http request header in angular 4 and angular 2?
Does google use angular?
What is the use of @Input and @Output?
Explain component specific hooks?
How AngularJS compilation is different from other JavaScript frameworks?
What is an async pipe?
How to append base url to http requests in angular?
What is inject in angular?
How would you pass data from a parent component to a child component?
How to install angular 8?