Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Bug: Changing the location outside of $location causes infdig and/or resets the original url #11075

Closed
@arcanis

Description

@arcanis

Hi,

As said in the title, if the location is changed from outside the $location service (but inside a digest cycle, and especially inside a $q.then callback), then Angular will break and there is two possible outcome, apparently random (maybe some kind of race condition?) :

  • Either Angular break with an infinite digest loop (and an empty watcher list)
  • Or Angular will reset the URL to the old one by going into this code branch

Here is a minimal showcase to reproduce this issue :

<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.13/angular.js"></script>

<script>
    angular.module( 'testApp', [ ] ).controller( 'testController', function ( $location, $q, $scope, $window ) {
        $scope.triggerThing = function ( ) {
            $q.when( ).then( function ( ) {
                $window.history.pushState( { }, null, '#/testfoo' );
                $scope.$broadcast( 'test' );
            } );
        };
    } );
</script>

<div ng-app="testApp">
    <div ng-controller="testController">
        <a ng-click="triggerThing()">Trigger</a>
    </div>
</div>

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions