Skip to content

Instantly share code, notes, and snippets.

@takahser
Last active December 29, 2017 14:22
Show Gist options
  • Save takahser/98e36675eb799cb9c49a767332a345bb to your computer and use it in GitHub Desktop.
Save takahser/98e36675eb799cb9c49a767332a345bb to your computer and use it in GitHub Desktop.
NativeScript

NativeScript

with Angular & TypeScript

CLI

# without template
tns create MyApp --ng

# with template
tns create MyApp --template tns-template-master-detail-ts

available ng templates:

  • tns-template-blank-ng
  • tns-template-drawer-navigation-ng
  • tns-template-tab-navigation-ng
  • tns-template-master-detail-ng
  • tns-template-master-detail-kinvey-ng

Resources:

UI Controls

https://docs.nativescript.org/ui/components

  • TextField

  • ActionBar => top bar on app https://docs.nativescript.org/angular/ui/action-bar

  • layout organization

  • GridLayout

    <!-- grid layout with two rows:
         1st child (GridLayout) will take up the size of its children (auto);
         2nd child (RadListView) will take up the rest of the size (*) -->
    <GridLayout rows="auto, *">
    
        <!-- 1st row (row0) -->
      <GridLayout row="0" columns="*, auto" class="add-bar">
        <TextField #groceryTextField hint="Enter a grocery item" col="0"></TextField>
        <Image src="~/images/add.png" col="1"></Image>
      </GridLayout>
    
      <!-- 2nd row (row1) -->
      <RadListView row="1" [items]="groceryList">
        <ng-template let-item="item">
          <Label [text]="item.name" class="p-15"></Label>
        </ng-template>
      </RadListView>
    
    </GridLayout>
    

     

Plugins

2-way-bindings

markup:

    <TextField [(ngModel)]="user.email"></TextField>

module:

import { NativeScriptFormsModule } from "nativescript-angular/forms";

@NgModule({
  imports: [
    NativeScriptFormsModule, // this is required for 2-way-bindings to work
  ],

NativeScriptHttpModule

:= a NativeScript wrapper of Angular’s HttpModule, a module that declares all of Angular’s HTTP-based services

import { NativeScriptHttpModule } from "nativescript-angular/http";
@NgModule({
  imports: [
    NativeScriptHttpModule
  ],

Routing

// app.routing.ts
import { LoginComponent } from "./login/login.component";

export const routes = [
  { path: "", component: LoginComponent }
];

export const navigatableComponents = [
  LoginComponent
];

// app.module.ts
import { NativeScriptRouterModule } from "nativescript-angular/router";

import { routes, navigatableComponents } from "./app.routing";

@NgModule({
  imports: [
    NativeScriptRouterModule,
    NativeScriptRouterModule.forRoot(routes)
  ],
  declarations: [
    AppComponent,
    ...navigatableComponents
  ],

// template
<page-router-outlet></page-router-outlet>

Other sources

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment