Revert "fix(router): RouterLinkActive should update its state right after checking the children (#19449)"

This reverts commit c569b75249.
As it was synched together with 5a9ed2de27
which broke an internal test.
This commit is contained in:
Tobias Bosch
2017-10-18 09:58:41 -07:00
parent 30ecb6e88a
commit b0c7ea8181
3 changed files with 16 additions and 68 deletions

View File

@ -118,19 +118,21 @@ export class RouterLinkActive implements OnChanges,
private update(): void {
if (!this.links || !this.linksWithHrefs || !this.router.navigated) return;
Promise.resolve().then(() => {
const hasActiveLinks = this.hasActiveLinks();
if (this.isActive !== hasActiveLinks) {
(this as any).isActive = hasActiveLinks;
this.classes.forEach((c) => {
if (hasActiveLinks) {
this.renderer.addClass(this.element.nativeElement, c);
} else {
this.renderer.removeClass(this.element.nativeElement, c);
}
});
}
});
const hasActiveLinks = this.hasActiveLinks();
// react only when status has changed to prevent unnecessary dom updates
if (this.isActive !== hasActiveLinks) {
this.classes.forEach((c) => {
if (hasActiveLinks) {
this.renderer.addClass(this.element.nativeElement, c);
} else {
this.renderer.removeClass(this.element.nativeElement, c);
}
});
Promise.resolve(hasActiveLinks).then(active => (this as{
isActive: boolean
}).isActive = active);
}
}
private isLinkActive(router: Router): (link: (RouterLink|RouterLinkWithHref)) => boolean {