refactor(router): remove usage of deprecated Renderer

This commit is contained in:
Pawel Kozlowski 2017-06-20 13:24:39 +02:00 committed by Matias Niemelä
parent e80851d98b
commit 3165fd3dc9
3 changed files with 14 additions and 9 deletions

View File

@ -7,7 +7,7 @@
*/
import {LocationStrategy} from '@angular/common';
import {Attribute, Directive, ElementRef, HostBinding, HostListener, Input, OnChanges, OnDestroy, Renderer, isDevMode} from '@angular/core';
import {Attribute, Directive, ElementRef, HostBinding, HostListener, Input, OnChanges, OnDestroy, Renderer2, isDevMode} from '@angular/core';
import {Subscription} from 'rxjs/Subscription';
import {QueryParamsHandling} from '../config';
@ -106,9 +106,9 @@ export class RouterLink {
constructor(
private router: Router, private route: ActivatedRoute,
@Attribute('tabindex') tabIndex: string, renderer: Renderer, el: ElementRef) {
@Attribute('tabindex') tabIndex: string, renderer: Renderer2, el: ElementRef) {
if (tabIndex == null) {
renderer.setElementAttribute(el.nativeElement, 'tabindex', '0');
renderer.setAttribute(el.nativeElement, 'tabindex', '0');
}
}

View File

@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import {AfterContentInit, ChangeDetectorRef, ContentChildren, Directive, ElementRef, Input, OnChanges, OnDestroy, QueryList, Renderer, SimpleChanges} from '@angular/core';
import {AfterContentInit, ChangeDetectorRef, ContentChildren, Directive, ElementRef, Input, OnChanges, OnDestroy, QueryList, Renderer2, SimpleChanges} from '@angular/core';
import {Subscription} from 'rxjs/Subscription';
import {NavigationEnd} from '../events';
import {Router} from '../router';
@ -91,7 +91,7 @@ export class RouterLinkActive implements OnChanges,
@Input() routerLinkActiveOptions: {exact: boolean} = {exact: false};
constructor(
private router: Router, private element: ElementRef, private renderer: Renderer,
private router: Router, private element: ElementRef, private renderer: Renderer2,
private cdr: ChangeDetectorRef) {
this.subscription = router.events.subscribe(s => {
if (s instanceof NavigationEnd) {
@ -123,8 +123,13 @@ export class RouterLinkActive implements OnChanges,
// react only when status has changed to prevent unnecessary dom updates
if (this.active !== hasActiveLinks) {
this.classes.forEach(
c => this.renderer.setElementClass(this.element.nativeElement, c, 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.active = active);
}
}

View File

@ -300,7 +300,7 @@ export declare class RouterLink {
routerLink: any[] | string;
skipLocationChange: boolean;
readonly urlTree: UrlTree;
constructor(router: Router, route: ActivatedRoute, tabIndex: string, renderer: Renderer, el: ElementRef);
constructor(router: Router, route: ActivatedRoute, tabIndex: string, renderer: Renderer2, el: ElementRef);
onClick(): boolean;
}
@ -313,7 +313,7 @@ export declare class RouterLinkActive implements OnChanges, OnDestroy, AfterCont
routerLinkActiveOptions: {
exact: boolean;
};
constructor(router: Router, element: ElementRef, renderer: Renderer, cdr: ChangeDetectorRef);
constructor(router: Router, element: ElementRef, renderer: Renderer2, cdr: ChangeDetectorRef);
ngAfterContentInit(): void;
ngOnChanges(changes: SimpleChanges): void;
ngOnDestroy(): void;