Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Implemented isRouteActive property of nsRouterLink
  • Loading branch information
vakrilov authored and NathanWalker committed Apr 2, 2016
commit a5273940ab6217d13b6c22b0ccfd6c4baa1b693c
2 changes: 2 additions & 0 deletions ng-sample/app/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {NavigationTest} from "./examples/navigation/navigation-test";
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";

nativeScriptBootstrap(RendererTest);
//nativeScriptBootstrap(Benchmark);
Expand All @@ -38,3 +39,4 @@ nativeScriptBootstrap(RendererTest);
// nativeScriptBootstrap(ActionBarTest, [NS_ROUTER_PROVIDERS], { startPageActionBarHidden: false });
// nativeScriptBootstrap(ModalTest);
// nativeScriptBootstrap(PlatfromDirectivesTest);
// nativeScriptBootstrap(RouterOutletTest, [NS_ROUTER_PROVIDERS]);
26 changes: 26 additions & 0 deletions ng-sample/app/examples/navigation/router-outlet-test.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
.title {
font-size: 30;
margin: 16;
color: darkslategray;
}

.nav {
orientation: horizontal;
horizontal-align: stretch;
padding: 4;
background-color: lightblue;
}

.link {
margin: 10 30;
horizontal-align: stretch;
}

.router-link-active {
background-color: lightcoral;
}

button {
horizontal-align: left;
margin: 0 6;
}
53 changes: 53 additions & 0 deletions ng-sample/app/examples/navigation/router-outlet-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import {Component} from 'angular2/core';
import {RouteConfig, ROUTER_PROVIDERS, ROUTER_DIRECTIVES, ComponentInstruction, RouteParams} from 'angular2/router';
import {NS_ROUTER_DIRECTIVES, NS_ROUTER_PROVIDERS} from "../../nativescript-angular/router/ns-router";

@Component({
selector: "first",
directives: [ROUTER_DIRECTIVES, NS_ROUTER_DIRECTIVES],
styleUrls: ["examples/navigation/router-outlet-test.css"],
template: `
<StackLayout>
<Label text="First component" class="title"></Label>
</StackLayout>`
})
class FirstComponent { }

@Component({
selector: "second",
directives: [ROUTER_DIRECTIVES, NS_ROUTER_DIRECTIVES],
styleUrls: ["examples/navigation/router-outlet-test.css"],
template: `
<StackLayout>
<Label [text]="'Second component - ' + id" class="title"></Label>
</StackLayout>`
})
class SecondComponent {
public id: string;
constructor(routeParams: RouteParams) {
this.id = routeParams.get("id");
}
}

@Component({
selector: 'navigation-test',
directives: [ROUTER_DIRECTIVES, NS_ROUTER_DIRECTIVES],
styleUrls: ["examples/navigation/router-outlet-test.css"],
template: `
<StackLayout>
<StackLayout class="nav">
<Button text="First" [nsRouterLink]="['First']"></Button>
<Button text="GO(1)" [nsRouterLink]="['Second', { id: 1 }]"></Button>
<Button text="GO(2)" [nsRouterLink]="['Second', { id: 2 }]"></Button>
<Button text="GO(3)" [nsRouterLink]="['Second', { id: 3 }]"></Button>
</StackLayout>

<router-outlet></router-outlet>
</StackLayout>
`
})
@RouteConfig([
{ path: '/first', component: FirstComponent, name: 'First', useAsDefault: true },
{ path: '/second/:id', component: SecondComponent, name: 'Second' },
])
export class RouterOutletTest { }
5 changes: 3 additions & 2 deletions src/nativescript-angular/router/ns-router-link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ import { log } from "./common";
selector: '[nsRouterLink]',
inputs: ['params: nsRouterLink'],
host: {
'(tap)': 'onTap()'
'(tap)': 'onTap()',
'[class.router-link-active]': 'isRouteActive'
}
})
export class NSRouterLink {
Expand All @@ -46,7 +47,7 @@ export class NSRouterLink {

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

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

set params(changes: any[]) {
this._routeParams = changes;
Expand Down