cleanup(router): fix tslint errors
This commit is contained in:
@ -1,13 +1,9 @@
|
||||
import {
|
||||
Directive,
|
||||
HostListener,
|
||||
HostBinding,
|
||||
Input,
|
||||
OnChanges
|
||||
} from '@angular/core';
|
||||
import {Directive, HostBinding, HostListener, Input, OnChanges} from '@angular/core';
|
||||
|
||||
import {Router} from '../router';
|
||||
import {ActivatedRoute} from '../router_state';
|
||||
|
||||
|
||||
/**
|
||||
* The RouterLink directive lets you link to specific parts of your app.
|
||||
*
|
||||
@ -37,7 +33,7 @@ import {ActivatedRoute} from '../router_state';
|
||||
export class RouterLink implements OnChanges {
|
||||
@Input() target: string;
|
||||
private commands: any[] = [];
|
||||
@Input() queryParams: {[k:string]:any};
|
||||
@Input() queryParams: {[k: string]: any};
|
||||
@Input() fragment: string;
|
||||
|
||||
// the url displayed on the anchor element.
|
||||
@ -49,7 +45,7 @@ export class RouterLink implements OnChanges {
|
||||
constructor(private router: Router, private route: ActivatedRoute) {}
|
||||
|
||||
@Input()
|
||||
set routerLink(data: any[] | string) {
|
||||
set routerLink(data: any[]|string) {
|
||||
if (Array.isArray(data)) {
|
||||
this.commands = <any>data;
|
||||
} else {
|
||||
@ -57,30 +53,24 @@ export class RouterLink implements OnChanges {
|
||||
}
|
||||
}
|
||||
|
||||
ngOnChanges(changes:{}):any {
|
||||
this.updateTargetUrlAndHref();
|
||||
}
|
||||
ngOnChanges(changes: {}): any { this.updateTargetUrlAndHref(); }
|
||||
|
||||
@HostListener("click")
|
||||
@HostListener('click')
|
||||
onClick(): boolean {
|
||||
// If no target, or if target is _self, prevent default browser behavior
|
||||
if (!(typeof this.target === "string") || this.target == '_self') {
|
||||
this.router.navigate(this.commands, {
|
||||
relativeTo: this.route,
|
||||
queryParams: this.queryParams,
|
||||
fragment: this.fragment
|
||||
});
|
||||
if (!(typeof this.target === 'string') || this.target == '_self') {
|
||||
this.router.navigate(
|
||||
this.commands,
|
||||
{relativeTo: this.route, queryParams: this.queryParams, fragment: this.fragment});
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private updateTargetUrlAndHref(): void {
|
||||
const tree = this.router.createUrlTree(this.commands, {
|
||||
relativeTo: this.route,
|
||||
queryParams: this.queryParams,
|
||||
fragment: this.fragment
|
||||
});
|
||||
const tree = this.router.createUrlTree(
|
||||
this.commands,
|
||||
{relativeTo: this.route, queryParams: this.queryParams, fragment: this.fragment});
|
||||
if (tree) {
|
||||
this.href = this.router.serializeUrl(tree);
|
||||
}
|
||||
|
@ -1,23 +1,24 @@
|
||||
import {Injector, Directive, ViewContainerRef, Attribute, ComponentRef, ComponentFactory, ResolvedReflectiveProvider, ReflectiveInjector} from '@angular/core';
|
||||
import {RouterOutletMap} from '../router_outlet_map';
|
||||
import {PRIMARY_OUTLET} from '../shared';
|
||||
import {Attribute, ComponentFactory, ComponentRef, Directive, ReflectiveInjector, ResolvedReflectiveProvider, ViewContainerRef} from "@angular/core";
|
||||
import {RouterOutletMap} from "../router_outlet_map";
|
||||
import {PRIMARY_OUTLET} from "../shared";
|
||||
|
||||
@Directive({selector: 'router-outlet'})
|
||||
export class RouterOutlet {
|
||||
private activated:ComponentRef<any>|null;
|
||||
public outletMap:RouterOutletMap;
|
||||
private activated: ComponentRef<any>|null;
|
||||
public outletMap: RouterOutletMap;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
constructor(parentOutletMap:RouterOutletMap, private location:ViewContainerRef,
|
||||
@Attribute('name') name:string) {
|
||||
constructor(
|
||||
parentOutletMap: RouterOutletMap, private location: ViewContainerRef,
|
||||
@Attribute('name') name: string) {
|
||||
parentOutletMap.registerOutlet(name ? name : PRIMARY_OUTLET, this);
|
||||
}
|
||||
|
||||
get isActivated(): boolean { return !!this.activated; }
|
||||
get component(): Object {
|
||||
if (!this.activated) throw new Error("Outlet is not activated");
|
||||
if (!this.activated) throw new Error('Outlet is not activated');
|
||||
return this.activated.instance;
|
||||
}
|
||||
|
||||
@ -28,8 +29,9 @@ export class RouterOutlet {
|
||||
}
|
||||
}
|
||||
|
||||
activate(factory: ComponentFactory<any>, providers: ResolvedReflectiveProvider[],
|
||||
outletMap: RouterOutletMap): void {
|
||||
activate(
|
||||
factory: ComponentFactory<any>, providers: ResolvedReflectiveProvider[],
|
||||
outletMap: RouterOutletMap): void {
|
||||
this.outletMap = outletMap;
|
||||
const inj = ReflectiveInjector.fromResolvedProviders(providers, this.location.parentInjector);
|
||||
this.activated = this.location.createComponent(factory, this.location.length, inj, []);
|
||||
|
Reference in New Issue
Block a user