refactor(angular): prefix all ionic components (#16618)

fixes #16550
This commit is contained in:
Manu MA
2018-12-07 00:39:07 +01:00
committed by GitHub
parent edf3659949
commit 28b40fc725
7 changed files with 316 additions and 316 deletions

View File

@ -0,0 +1,55 @@
import { Directive, ElementRef, HostListener, Input, Optional } from '@angular/core';
import { NavController, NavDirection } from '../../providers/nav-controller';
import { Router, RouterLink } from '@angular/router';
import { LocationStrategy } from '@angular/common';
import { Subscription } from 'rxjs';
@Directive({
selector: '[routerLink]',
})
export class RouterLinkDelegate {
private subscription?: Subscription;
@Input() routerDirection: NavDirection = 'forward';
constructor(
private router: Router,
private locationStrategy: LocationStrategy,
private navCtrl: NavController,
private elementRef: ElementRef,
@Optional() private routerLink?: RouterLink,
) { }
ngOnInit() {
this.updateTargetUrlAndHref();
}
ngOnChanges(): any {
this.updateTargetUrlAndHref();
}
ngOnDestroy(): any {
if (this.subscription) {
this.subscription.unsubscribe();
}
}
private updateTargetUrlAndHref() {
if (this.routerLink) {
const href = this.locationStrategy.prepareExternalUrl(this.router.serializeUrl(this.routerLink.urlTree));
console.log(href);
this.elementRef.nativeElement.href = href;
}
}
@HostListener('click', ['$event'])
onClick(ev: UIEvent) {
if (this.routerDirection) {
this.navCtrl.setDirection(this.routerDirection);
}
ev.preventDefault();
}
}