Skip to content

Commit

Permalink
refactor(router): change RouterLinkActive impl to account for upcomin…
Browse files Browse the repository at this point in the history
…g ivy breaking change (#28560)

PR Close #28560
  • Loading branch information
pkozlowski-opensource authored and mhevery committed Feb 9, 2019
1 parent e9bedc6 commit fcd1f61
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
11 changes: 7 additions & 4 deletions packages/router/src/directives/router_link_active.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* 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 {NavigationEnd, RouterEvent} from '../events';
Expand Down Expand Up @@ -93,7 +93,8 @@ export class RouterLinkActive implements OnChanges,

constructor(
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) => {
if (s instanceof NavigationEnd) {
this.update();
Expand Down Expand Up @@ -140,7 +141,9 @@ export class RouterLinkActive implements OnChanges,
}

private hasActiveLinks(): boolean {
return this.links.some(this.isLinkActive(this.router)) ||
this.linksWithHrefs.some(this.isLinkActive(this.router));
const isActiveCheckFn = this.isLinkActive(this.router);
return this.link && isActiveCheckFn(this.link) ||
this.linkWithHref && isActiveCheckFn(this.linkWithHref) ||
this.links.some(isActiveCheckFn) || this.linksWithHrefs.some(isActiveCheckFn);
}
}
1 change: 0 additions & 1 deletion packages/router/test/integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3578,7 +3578,6 @@ describe('Integration', () => {

TestBed.configureTestingModule({declarations: [RootCmpWithLink]});
const router: Router = TestBed.get(Router);
const loc: any = TestBed.get(Location);

const f = TestBed.createComponent(RootCmpWithLink);
advance(f);
Expand Down
2 changes: 1 addition & 1 deletion tools/public_api_guard/router/router.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ export declare class RouterLinkActive implements OnChanges, OnDestroy, AfterCont
routerLinkActiveOptions: {
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;
ngOnChanges(changes: SimpleChanges): void;
ngOnDestroy(): void;
Expand Down

0 comments on commit fcd1f61

Please sign in to comment.