refactor(router): change RouterLinkActive impl to account for upcoming ivy breaking change (#28560)
PR Close #28560
This commit is contained in:
parent
e9bedc63bb
commit
fcd1f61476
@ -6,7 +6,7 @@
|
|||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {AfterContentInit, ChangeDetectorRef, ContentChildren, Directive, ElementRef, Input, OnChanges, OnDestroy, QueryList, Renderer2, SimpleChanges} from '@angular/core';
|
import {AfterContentInit, ContentChildren, Directive, ElementRef, Input, OnChanges, OnDestroy, Optional, QueryList, Renderer2, SimpleChanges} from '@angular/core';
|
||||||
import {Subscription} from 'rxjs';
|
import {Subscription} from 'rxjs';
|
||||||
|
|
||||||
import {NavigationEnd, RouterEvent} from '../events';
|
import {NavigationEnd, RouterEvent} from '../events';
|
||||||
@ -93,7 +93,8 @@ export class RouterLinkActive implements OnChanges,
|
|||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private router: Router, private element: ElementRef, private renderer: Renderer2,
|
private router: Router, private element: ElementRef, private renderer: Renderer2,
|
||||||
private cdr: ChangeDetectorRef) {
|
@Optional() private link?: RouterLink,
|
||||||
|
@Optional() private linkWithHref?: RouterLinkWithHref) {
|
||||||
this.subscription = router.events.subscribe((s: RouterEvent) => {
|
this.subscription = router.events.subscribe((s: RouterEvent) => {
|
||||||
if (s instanceof NavigationEnd) {
|
if (s instanceof NavigationEnd) {
|
||||||
this.update();
|
this.update();
|
||||||
@ -140,7 +141,9 @@ export class RouterLinkActive implements OnChanges,
|
|||||||
}
|
}
|
||||||
|
|
||||||
private hasActiveLinks(): boolean {
|
private hasActiveLinks(): boolean {
|
||||||
return this.links.some(this.isLinkActive(this.router)) ||
|
const isActiveCheckFn = this.isLinkActive(this.router);
|
||||||
this.linksWithHrefs.some(this.isLinkActive(this.router));
|
return this.link && isActiveCheckFn(this.link) ||
|
||||||
|
this.linkWithHref && isActiveCheckFn(this.linkWithHref) ||
|
||||||
|
this.links.some(isActiveCheckFn) || this.linksWithHrefs.some(isActiveCheckFn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3578,7 +3578,6 @@ describe('Integration', () => {
|
|||||||
|
|
||||||
TestBed.configureTestingModule({declarations: [RootCmpWithLink]});
|
TestBed.configureTestingModule({declarations: [RootCmpWithLink]});
|
||||||
const router: Router = TestBed.get(Router);
|
const router: Router = TestBed.get(Router);
|
||||||
const loc: any = TestBed.get(Location);
|
|
||||||
|
|
||||||
const f = TestBed.createComponent(RootCmpWithLink);
|
const f = TestBed.createComponent(RootCmpWithLink);
|
||||||
advance(f);
|
advance(f);
|
||||||
|
2
tools/public_api_guard/router/router.d.ts
vendored
2
tools/public_api_guard/router/router.d.ts
vendored
@ -390,7 +390,7 @@ export declare class RouterLinkActive implements OnChanges, OnDestroy, AfterCont
|
|||||||
routerLinkActiveOptions: {
|
routerLinkActiveOptions: {
|
||||||
exact: boolean;
|
exact: boolean;
|
||||||
};
|
};
|
||||||
constructor(router: Router, element: ElementRef, renderer: Renderer2, cdr: ChangeDetectorRef);
|
constructor(router: Router, element: ElementRef, renderer: Renderer2, link?: RouterLink | undefined, linkWithHref?: RouterLinkWithHref | undefined);
|
||||||
ngAfterContentInit(): void;
|
ngAfterContentInit(): void;
|
||||||
ngOnChanges(changes: SimpleChanges): void;
|
ngOnChanges(changes: SimpleChanges): void;
|
||||||
ngOnDestroy(): void;
|
ngOnDestroy(): void;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user