Skip to content

Commit

Permalink
Merge pull request #368 from ggaulard/master
Browse files Browse the repository at this point in the history
Fix directive for route active
  • Loading branch information
PatrickJS committed Mar 1, 2016
2 parents 95b7ecc + bb1bb5b commit 889d175
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/app/directives/router-active.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,27 @@ export class RouterActive {
}

ngOnInit() {
this.router.subscribe(() => {
this.routerLink.changes.subscribe(() => {
if (this.routerLink.first) {
let active = this.routerLink.first.isRouteActive;
this.renderer.setElementClass(this.element.nativeElement, this._attrOrProp(), active);
this._updateClass();
this._findRootRouter().subscribe(() => {
this._updateClass();
});
}
});
}

private _findRootRouter(): Router{
var router: Router = this.router;
while (isPresent(router.parent)) {
router = router.parent;
}
return router;
}

private _updateClass(){
let active = this.routerLink.first.isRouteActive;
this.renderer.setElementClass(this.element.nativeElement, this._attrOrProp(), active);
}

private _defaultAttrValue(attr?: string) {
Expand Down

0 comments on commit 889d175

Please sign in to comment.