![]() |
AngularJS is a JavaScript-based framework. It can be used by adding it to an HTML page using a <script> tag. AngularJS helps in extending the HTML attributes with the help of directives and binding of data to the HTML with expressions. In this article, we’ll learn about the AngularJS $qProvider. The $qProvider is a provider that allows you to configure the behavior of the $q service, which is the AngularJS implementation of promises. The $qProvider provides methods to control and customize the default settings of promises. Method used:
Return value: It returns the boolean value for the current value, while without invoking the new value, otherwise forms chaining for self. Approach 1: Promise Creation and HandlingSyntax: app.config(function ($qProvider) { Example: In this example, we have configured the $qProvider to disable the generation of errors when a rejected promise is not handled using the errorOnUnhandledRejections(false) method in the app.config() function. By setting this option, AngularJS won’t throw an error when a promise rejection is not explicitly handled. HTML
Output: Approach 2: Using $qProvider.errorOnUnhandledRejections() methodSyntax: app.controller("PromiseController", function ($scope, $q) { Example: In this example, we have used a controller PromiseController that uses the $q service to create a promise. Here, inside the dataLoad() function, we have used the setTimeout() to simulate an asynchronous operation that resolves the promise after 1 second. The resolved data is then assigned to the $scope.mydata variable using the then() method. HTML
Output: Reference: https://docs.angularjs.org/api/ng/provider/$qProvider |
Reffered: https://www.geeksforgeeks.org
AngularJS |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 10 |