Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions ng-sample/app/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import { NS_ROUTER_PROVIDERS, routerTraceCategory } from "./nativescript-angular
import { rendererTraceCategory } from "./nativescript-angular/renderer";

import trace = require("trace");
// trace.setCategories(routerTraceCategory + ", " + rendererTraceCategory);
//trace.setCategories(routerTraceCategory + ", " + rendererTraceCategory);
// trace.setCategories(rendererTraceCategory);
// trace.setCategories(routerTraceCategory);
trace.setCategories(routerTraceCategory);
trace.enable();

import {RendererTest} from './examples/renderer-test';
Expand All @@ -27,8 +27,9 @@ import {ActionBarTest} from "./examples/action-bar/action-bar-test";
import {ModalTest} from "./examples/modal/modal-test";
import {PlatfromDirectivesTest} from "./examples/platform-directives/platform-directives-test";
import {RouterOutletTest} from "./examples/navigation/router-outlet-test";
import {LoginTest} from "./examples/navigation/login-test";

nativeScriptBootstrap(RendererTest);
//nativeScriptBootstrap(RendererTest);
//nativeScriptBootstrap(TabViewTest);
//nativeScriptBootstrap(Benchmark);
//nativeScriptBootstrap(ListTest);
Expand All @@ -40,3 +41,4 @@ nativeScriptBootstrap(RendererTest);
//nativeScriptBootstrap(ModalTest);
//nativeScriptBootstrap(PlatfromDirectivesTest);
//nativeScriptBootstrap(RouterOutletTest, [NS_ROUTER_PROVIDERS]);
nativeScriptBootstrap(LoginTest, [NS_ROUTER_PROVIDERS]);
70 changes: 70 additions & 0 deletions ng-sample/app/examples/navigation/login-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import {Component} from '@angular/core';
import {RouteConfig, ROUTER_PROVIDERS, ROUTER_DIRECTIVES, ComponentInstruction, Router, RouteParams, RouteData} from '@angular/router-deprecated';
import {NS_ROUTER_DIRECTIVES, NS_ROUTER_PROVIDERS} from "../../nativescript-angular/router/ns-router";
import {isBlank} from '@angular/core/src/facade/lang';

@Component({
selector: 'login-page',
directives: [NS_ROUTER_DIRECTIVES],
template: `
<StackLayout>
<StackLayout orientation='horizontal'>
<Label text="user: "></Label>
<TextField text="user"></TextField>
</StackLayout>
<StackLayout orientation='horizontal'>
<Label text="pass: "></Label>
<TextField text="pass"></TextField>
</StackLayout>
<Button text='Login' (tap)="onLoginTap()"></Button>
</StackLayout>
`
})
export class LoginPage {
private router: Router;
constructor(private _router: Router){
this.router = _router;
}
onLoginTap(args) {
this.router.navigate(["Main", { "success" : true }]);
}
}

@Component({
selector: 'main',
directives: [NS_ROUTER_DIRECTIVES],
template: `
<TextField text="Main Content"></TextField>
`
})
export class MainComponent {
private getParamOrData(key: string, params: RouteParams, data: RouteData) {
let result = params.get(key);
if (!isBlank(result)) {
return result;
} else {
return data.get(key);
}
}

constructor(params: RouteParams, private _router: Router, private _data: RouteData) {
let success = this.getParamOrData("success", params, _data);
if (!success) {
_router.navigate(["Login"]);
}
console.log("params: " + params);
}
}

@Component({
selector: 'login-test',
directives: [NS_ROUTER_DIRECTIVES],
template: `<page-router-outlet></page-router-outlet>`
})
@RouteConfig([
{ path: '/login', component: LoginPage, name: 'Login' },
{ path: '/main', component: MainComponent, name: 'Main', data: {"success": false}, useAsDefault: true },
])
export class LoginTest {

}
3 changes: 1 addition & 2 deletions src/nativescript-angular/router/ns-router-link.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {Directive, Input} from '@angular/core';
import {isString} from '@angular/core/src/facade/lang';
import {Router, Instruction} from '@angular/router-deprecated';
import {Location} from '@angular/common';
import { log } from "./common";

/**
Expand Down Expand Up @@ -46,7 +45,7 @@ export class NSRouterLink {
// the instruction passed to the router to navigate
private _navigationInstruction: Instruction;

constructor(private _router: Router, private _location: Location) { }
constructor(private _router: Router) { }

get isRouteActive(): boolean { return this._router.isRouteActive(this._navigationInstruction); }

Expand Down