Integrating NativeScript with Angular 2.
The project bundles the NativeScript modules and Angular as source code dependencies set up as git submodules. You need to get them by running:
$ git submodule update --init
You will need the Android SDK to build this project. Install it manually.
Then install the NativeScript tools according to: this article.
Then install the needed NPM packages:
$ npm install
$ (cd deps/angular/modules/angular2 && tsd reinstall)
$ grunt prepare
$ grunt shell:ngSampleInit
$ grunt ng-sample
- Make some changes to the app or
src/nativescript-angular
- Navigate to the ng-sample subdir:
$ cd ng-sample
- Compile app:
$ grunt app
- Run in emulator
$ tns emulate android --avd <YOUR-AVD>
Protip: combine #2 and #3 above in a single command run from the project root directory (works only on Unixy shells):
$ (cd ng-sample && grunt app && tns emulate android --avd nexus4-x64)
On Windows, you can wrap those commands in a BAT file.
- The
./src/nativescript-angular
folder holds the integration source code. - The sample app below
ng-sample
is assembled by copying typescript dependencies in itssrc
folder:- angular2 source code
- nativescript-angular code
- NativeScript typings: typings/nativescript
- All required JavaScript packages (including compiled NativeScript modules) are copied to
ng-sample/app/tns_modules
- Use the Angular Parse5DomAdapter to parse component markup.
- Provide a custom renderer (
NativeScriptRenderer
) that works with the parsed DOM and creates NativeScript UI elements. Only limited number of visual elements supported so far.
- The renderer code needs to be cleaned up and made extensible, so that people can register new visual elements.
- There are certain issues with the Parse5DomAdapter and we'll likely need to provide our own later on:
- Element and attribute names always get lowercased.
- Self-closing elements (
<Label text="Name" /><Button text="Save" />
) get parsed wrong (in this case Button gets parsed as a Label child.
- The renderer implementation is by no means complete: we are still need to support view (de)hydration, DOM text updates, event dispatching, actions, etc.