feat(angular): href integration

This commit is contained in:
Manu Mtz.-Almeida
2018-04-03 18:51:32 +02:00
parent 926c8859ce
commit 09e6b7e4a2
3 changed files with 32 additions and 0 deletions

View File

@ -11,6 +11,7 @@ export { NavDelegate } from './navigation/nav-delegate';
export { TabDelegate } from './navigation/tab-delegate';
export { TabsDelegate } from './navigation/tabs-delegate';
export { IonRouterOutlet } from './navigation/ion-router-outlet';
export { HrefDelegate } from './navigation/href-delegate';
export { Icon } from './icon';
export { VirtualScroll } from './virtual-scroll/virtual-scroll';

View File

@ -0,0 +1,30 @@
import { Directive, ElementRef, HostListener, Input, Optional } from '@angular/core';
import { Router } from '@angular/router';
@Directive({
selector: 'ion-anchor,ion-button,ion-item'
})
export class HrefDelegate {
@Input()
set href(value: string) {
this.elementRef.nativeElement.href = value;
}
get href() {
return this.elementRef.nativeElement.href;
}
constructor(
@Optional() private router: Router,
private elementRef: ElementRef
) {}
@HostListener('click', ['$event'])
onClick(ev: Event) {
const url = this.href;
if (this.router && url && url[0] !== '#' && url.indexOf('://') === -1) {
ev.preventDefault();
this.router.navigateByUrl(url);
}
}
}

View File

@ -100,6 +100,7 @@ const DECLARATIONS = [
c.NavDelegate,
c.TabDelegate,
c.TabsDelegate,
c.HrefDelegate,
// virtual scroll
c.VirtualFooter,