Giter Club home page Giter Club logo

angular-cancel-on-navigate's People

Contributors

albertbrand avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

angular-cancel-on-navigate's Issues

Code change request.

This modified source code solves 2 problems.

  1. If cancelOnRouteChange isn't defined, the call isn't cancelled. This is specially important when loading angular app directives. I have a redirect to login would cancel the loading of important app directives. The default behaviour should be not to cancel.
  2. Cancelled calls were hanging the angular-loading-bar. So loading would never finish.

I didn't create a PR because these changes are easy to implement. Source code below:

  angular
  .module('angularCancelOnNavigateModule', [])
  .config(function($httpProvider) {
    $httpProvider.interceptors.push('HttpRequestTimeoutInterceptor');
  })
  .run(function ($rootScope, HttpPendingRequestsService) {
    $rootScope.$on('$locationChangeSuccess', function (event, newUrl, oldUrl) {
      if (newUrl != oldUrl) {
        HttpPendingRequestsService.cancelAll();
      }
    });
  });

angular.module('angularCancelOnNavigateModule')
  .service('HttpPendingRequestsService', function ($q) {
    var cancelPromises = [];

    function newTimeout() {
      var cancelPromise = $q.defer();
      cancelPromises.push(cancelPromise);
      return cancelPromise.promise;
    }

    function cancelAll() {
      angular.forEach(cancelPromises, function (cancelPromise) {
        cancelPromise.promise.isGloballyCancelled = true;
        cancelPromise.resolve();
      });
      cancelPromises.length = 0;
    }

    return {
      newTimeout: newTimeout,
      cancelAll: cancelAll
    };
  });

angular.module('angularCancelOnNavigateModule')
  .factory('HttpRequestTimeoutInterceptor', function ($q, HttpPendingRequestsService) {
    return {
      request: function (config) {
        config = config || {};
        if (config.timeout === undefined && config.cancelOnRouteChange) {
          config.timeout = HttpPendingRequestsService.newTimeout();
        }
        return config;
      },

      responseError: function (response) {
        return $q.reject(response);
      }
    };
  });

Canceling Previous HTTP Request when changing module

Hi,

Here's my objective, i want to cancel all HTTP request from my previous when im going to another module. Something like this dashboard > company.

I want to cancel all HTTP request form dashboard module when i successfully change module. If this possible please guide me.

Thanks in advance for your help.

Emman

Support minification

The dependency injection breaks when you minify the file. I believe the minified file included in the build directory is also broken.

NPM release

Hello,

note sure if this project is still active or not . In case it is, would it be possible to have an NPM release?

Usage with ui-router

Hi, I was very frustrated at first because this library wasn't working OK, but after a while I realized that this module uses $locationChangeSuccess event.

Because I'm using ui-router with states, I simple had to replace that event name with '$stateChangeSuccess' and that solved my issue.

I think it could be helpful for others to make this observation in your README, cause ui-router is basically a standard on these days.

Thanks for the library anyway!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.