Skip to content

dvalsagna89/interceptorModule

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 

Repository files navigation

interceptorModule

A module for AngularJS that allows to catch HTML responses and show messages according to the status code and the target url.

How to use

You need:

  • AngularJS
  • Angular Material (the module use $mdDialog to show messages)
  • Loader

Steps:

  • Add interceptor.module.js to your index.html
  • Inject "interceptorModule" in your main module
  • Add the following lines to your main module:
    app.factory('resourceInterceptor', ['$rootScope', function ($rootScope) {
      return {
          response: function (response) {
              $rootScope.$broadcast('showMessage', response);
              return response;
          },
          responseError: function (response) {
              $rootScope.$broadcast('showMessage', response);
              return response;
          }
      }
    }]);
    
    app.config(['$httpProvider', function ($httpProvider) {
        $httpProvider.interceptors.push('resourceInterceptor');
    }]);
  • Add the loader you want. A div tag with id="loader" is needed. I'm using one from this page: https://icons8.com/cssload

What I learned

  • HTTP Status codes
  • Catch HTTP response data
  • Using promises
  • Showing messages using a dialog

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published