Skip to content
This repository was archived by the owner on Oct 22, 2018. It is now read-only.

Commit 621b46a

Browse files
committed
Fix the navigation using RouterExtensions
1 parent b431795 commit 621b46a

File tree

6 files changed

+41
-16
lines changed

6 files changed

+41
-16
lines changed

src/app/about/components/about/about.component.tns.html

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
<Page>
2-
<ActionBarExtension>
3-
<NavigationButton visibility="collapsed"></NavigationButton>
4-
<ActionItem ios.position="left">
5-
<Button class="ion-icon" text="{{ '\uF30C' }}" [nsRouterLink]="['/home']" clearHistory="true"></Button>
2+
<ActionBar title="About">
3+
<ActionItem ios.position="left" (tap)="backPage()">
4+
<Button class="ion-icon" text="{{ '\uF30C' }}"></Button>
65
</ActionItem>
7-
</ActionBarExtension>
6+
</ActionBar>
87
<StackLayout>
98
<Label class="h1 title" text="About me!"></Label>
109
</StackLayout>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { Component, OnInit } from '@angular/core';
2+
import { RouterExtensions } from "nativescript-angular/router";
3+
4+
@Component({
5+
moduleId: module.id,
6+
selector: 'about-page',
7+
templateUrl: './about.component.html',
8+
styleUrls: ['./about.component.scss']
9+
})
10+
export class AboutComponent implements OnInit {
11+
12+
constructor(private _router: RouterExtensions) { }
13+
14+
ngOnInit() {
15+
}
16+
17+
backPage() {
18+
this._router.back()
19+
}
20+
}

src/app/about/components/about/about.component.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Component, OnInit } from '@angular/core';
2+
import { Router } from '@angular/router';
23

34
@Component({
45
moduleId: module.id,
@@ -8,9 +9,12 @@ import { Component, OnInit } from '@angular/core';
89
})
910
export class AboutComponent implements OnInit {
1011

11-
constructor() { }
12+
constructor(private _router: Router) { }
1213

1314
ngOnInit() {
1415
}
1516

17+
openPage(url) {
18+
this._router.navigate([url])
19+
}
1620
}

src/app/app.component.tns.html

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
<ActionBar title="NativeScript Mobile App, yay!">
2-
</ActionBar>
31
<StackLayout class="container" row="1">
42
<router-outlet></router-outlet>
53
</StackLayout>

src/app/home/components/home/home.component.tns.html

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
<Page xmlns:Card="nativescript-cardview">
2-
<ActionBarExtension>
3-
<ActionItem ios.position="right">
4-
<Button class="ion-icon" [nsRouterLink]="['/about']" text="{{ '\uf41a' }}"></Button>
2+
<ActionBar title="NativeScript Mobile App, yay!">
3+
<ActionItem ios.position="right" (tap)="openPage('/about')">
4+
<Button class="ion-icon" text="{{ '\uf41a' }}"></Button>
55
</ActionItem>
6-
</ActionBarExtension>
6+
</ActionBar>
77
<scroll-view>
88
<GridLayout rows="auto, *">
9-
<SearchBar row="0" hint="Search hint" [text]="Search"></SearchBar>
10-
<StackLayout row="1">
9+
<SearchBar row="0" hint="Search hint"></SearchBar>
10+
<StackLayout row="3">
11+
<Button text="Issue navigating to About page using nsRouterLink" [nsRouterLink]="['/about']"></Button>
1112
<Card:CardView class="cardStyle" radius="10" elevation="50" margin="20">
1213
<grid-layout rows="*, *, *" columns="*, *, *">
13-
<Image (click)="openPage()" src="http://ionicframework.com/img/home/cta-iphone-2.png" margin="20" stretch="aspectFill" colSpan="3" row="0"></Image>
14+
<Image src="http://ionicframework.com/img/home/cta-iphone-2.png" margin="20" stretch="aspectFill" colSpan="3" row="0"></Image>
1415
<TextView class="description" editable="false" text="The most popular template to create web (Ionic) and native (NativeScript) mobile apps!" textWrap="true" row="1" colSpan="3"></TextView>
1516
<Button text="Favorite" tap="goAway" row="3" col="0"></Button>
1617
<Button text="Listen" row="3" col="1"></Button>

src/app/home/components/home/home.component.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export class HomeComponent implements OnInit {
1515

1616
}
1717

18-
openPage(url) {
18+
showAlert() {
1919
let options = {
2020
title: "Race selection",
2121
message: "Race chosen: Unicorn",
@@ -24,4 +24,7 @@ export class HomeComponent implements OnInit {
2424
alert(options);
2525
}
2626

27+
openPage(url) {
28+
this._router.navigate([url])
29+
}
2730
}

0 commit comments

Comments
 (0)