fix(common): update $locationShim to notify onChange listeners before emitting AngularJS events (#32037)
The $locationShim has onChange listeners to allow for synchronization logic between AngularJS and Angular. When the AngularJS routing events are emitted first, this can cause Angular code to be out of sync. Notifying the listeners earlier solves the problem. PR Close #32037
This commit is contained in:

committed by
Kara Erickson

parent
bef27f2a28
commit
5064dc75ac
@ -144,6 +144,7 @@ export class $locationShim {
|
||||
this.$$parse(oldUrl);
|
||||
this.state(oldState);
|
||||
this.setBrowserUrlWithFallback(oldUrl, false, oldState);
|
||||
this.$$notifyChangeListeners(this.url(), this.$$state, oldUrl, oldState);
|
||||
} else {
|
||||
this.initalizing = false;
|
||||
$rootScope.$broadcast('$locationChangeSuccess', newUrl, oldUrl, newState, oldState);
|
||||
@ -199,6 +200,9 @@ export class $locationShim {
|
||||
}
|
||||
$rootScope.$broadcast(
|
||||
'$locationChangeSuccess', newUrl, oldUrl, this.$$state, oldState);
|
||||
if (urlOrStateChanged) {
|
||||
this.$$notifyChangeListeners(this.url(), this.$$state, oldUrl, oldState);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -415,7 +419,6 @@ export class $locationShim {
|
||||
// state object; this makes possible quick checking if the state changed in the digest
|
||||
// loop. Checking deep equality would be too expensive.
|
||||
this.$$state = this.browserState();
|
||||
this.$$notifyChangeListeners(url, state, oldUrl, oldState);
|
||||
} catch (e) {
|
||||
// Restore old values if pushState fails
|
||||
this.url(oldUrl);
|
||||
|
Reference in New Issue
Block a user