Skip to content

Commit

Permalink
feat(angular): href integration
Browse files Browse the repository at this point in the history
  • Loading branch information
manucorporat committed Apr 3, 2018
1 parent 926c885 commit 09e6b7e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions angular/src/directives/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
30 changes: 30 additions & 0 deletions angular/src/directives/navigation/href-delegate.ts
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
1 change: 1 addition & 0 deletions angular/src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ const DECLARATIONS = [
c.NavDelegate,
c.TabDelegate,
c.TabsDelegate,
c.HrefDelegate,

// virtual scroll
c.VirtualFooter,
Expand Down

0 comments on commit 09e6b7e

Please sign in to comment.