| Start |
|---|
| Generic httpInterceptor step by step Create an HTML file with the following content: Add a JavaScript file called 'app.js': Add another one called 'appController.js': And finally the file containing the interceptor itself 'genericInterceptor.js': The 'genericInterceptor' cover the possible functions which we can override adding extra behavior to our application. |
| Getting Started Angular's builtin |
Flash message on response using http interceptor In the view fileIn the base html (index.html) where we usually include the angular scripts or the html that is shared across the app, leave an empty div element, the flash messages will be appearing inside this div element Script FileIn the config method of angular module, inject the httpProvider, the httpProvider has an interceptor array property, push the custom interceptor, In the current example the custom interceptor intercepts only the response and calls a method attached to rootScope. Since only providers can be injected into the config method of an angular module (that is httpProvider and not the rootscope), declare the method attached to rootscope inside the run method of angular module. Also display the message inside $timeout so that the message will have the flash property, that is disappearing after a threshold time. In our example its 3000 ms. Common pitfallsTrying to inject $rootScope or any other services inside config method of angular module, the lifecycle of angular app doesnt allow that and unknown provider error will be thrown. Only providers can be injected in config method of the angular module |
Read Article
https://develop.horje.com/learn/1434/reference