Install Angular CLI
You should be using @angular/[email protected] or newer.
npm i -g @angular/cli
Install NativeScript Schematics
npm i -g @nativescript/schematics
Prerequisites for using @nativescript/schematics in an existing project
You need to add an angular.json configuration file to your NativeScript project root directory. That will allow you to use Angular CLI for generating components.
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"cli": {
"defaultCollection": "@nativescript/schematics"
},
"projects": {
"project-name": {
"root": "",
"sourceRoot": ".",
"projectType": "application",
"prefix": "app"
}
},
"defaultProject": "project-name"
}
Note: If you created your project with ng new, your project already has angular.json.
Generate angular.json
You can generate it the configuration using Schematics.
Install Schematics globally
npm install -g @angular-devkit/schematics-cli
From inside your project call:
schematics @nativescript/schematics:angular-json --name=project-name
Generating Components, Modules, Directives, etc.
You can use the ng generate (or just ng g) command to generate pretty much any Angular building unit - components, modules, directives, classes and so on. For the full list, check out the Angular CLI repo.
Some of these generators are overwritten in NativeScript Schematics to suite the needs of a NativeScript Angular application.
To generate a component, call:
ng g c component-name
To generate a module, call:
ng g m module-name
To generate a component in an existing module folder, call:
ng g c module-name/component-name
ng generate component
in my NativeScript app. – Killjoy