concept new page in category nativescript
appears as: new page, new pages

This is an excerpt from Manning's book NativeScript in Action.
Change the starting page of your app to a new page named home-page.
Move the birth date picker element to a new page.
Listing 17.9 The detail.component.ts file loading route value parameters and handling the onDoneTap() event
import { Component, OnInit } from "@angular/core"; import { Page } from "../../models/page"; import { RouterExtensions, PageRoute } from "nativescript-angular/router"; #1 import { NavigationOptions } from "nativescript-angular/router/ns-location-strategy"; import { PageService } from "../../services/page.service"; import "rxjs/add/operator/switchMap"; #1 @Component({ selector: "detail", providers: [ PageService ], templateUrl: "views/detail/detail.html", styleUrls: ["views/detail/detail.css"] }) export class DetailComponent implements OnInit { page: Page; #2 constructor( private routerExtensions: RouterExtensions, private pageService: PageService, private pageRoute: PageRoute) { } ngOnInit(): void { let id:number; #3 this.pageRoute.activatedRoute #3 .switchMap(activatedRoute => activatedRoute.params) #3 .forEach((params) => { #3 id = +params["id"]; #3 }); #3 this.page = this.pageService.getPage(id); #4 if (this.page === null) { #4 this.page = <Page>{ Id: id }; #4 } #4 } onDoneTap(): void { #5 this.pageService.savePage(this.page); var options = <NavigationOptions>{ clearHistory: true }; this.routerExtensions.navigate(["list"], options); } } #1 PageRoute and the rxjs module are needed to parse the route parameters #2 A scrapbook page is stored in the component for databinding #3 On init, get the id field passed via a route parameter #4 If a page can’t be loaded via its id, create a new page with that id #5 When done, save the scrapbook page and navigate back to the List component