node.js - How to generate a component in Nativescript 8 and angular - TagMerge
4How to generate a component in Nativescript 8 and angularHow to generate a component in Nativescript 8 and angular

How to generate a component in Nativescript 8 and angular

Asked 10 months ago
1
4 answers

You're missing angular.json in your project. And did you already install NativeScript Schematics? (npm i --save-dev @nativescript/schematics)

The file should have the following content:

{
    "version": 1,
    "cli": {
        "defaultCollection": "@nativescript/schematics"
    },
    "projects": {
        "my-project-name": {
            "root": "",
            "sourceRoot": "src",
            "projectType": "application",
            "prefix": "ns"
        }
    },
    "defaultProject": "my-project-name"
}

Replace my-project-name with the name of your project and run the generate command again.

NativeScript Documentation

Source: link

0

I use Add Angular Native Files with Visual Studio code. Pretty much works like ng g c componentName. You will just need to add the component to app.module.ts

More info here:

https://marketplace.visualstudio.com/items?itemName=joshdsommer.vscode-add-angular-native-files

Source: link

0

I just install all the requirements and setup my new Mac with Apple Silicon M1 Chip for Nativescript 8 development following their guide on https://nativescript.org. Now I created a new project running the command:
ns create
This asks for a name and what flavor you want, I choose Angular. Now I want to start creating new components but when trying to run the following command:
ng g c my-component
The file should have the following content:
{
    "version": 1,
    "cli": {
        "defaultCollection": "@nativescript/schematics"
    },
    "projects": {
        "my-project-name": {
            "root": "",
            "sourceRoot": "src",
            "projectType": "application",
            "prefix": "ns"
        }
    },
    "defaultProject": "my-project-name"
}

Source: link

0

To create a new NativeScript Angular application, run the CLI command ns create with the name of the application followed by --ng.
ns create example-app --ng
Go to the project's directory and run the following command to run it on the respective platforms.
cd example-app

// run on iOS
ns run ios

// run on Android
ns run android
Based on the Angular starter app, we will be creating the following file/folder structure for our application.
src/app
  |- assets
    |- anastasia.png
    |- beetlejuicemusical.png
    |- bookofmormon.png
  |- core
    |- models
      |- flick.model.ts
    |- services
      |- flick.service.ts
  |- features
    |- home
      |- home.component.ts | html
      |- home.module.ts
      |- home-routing.module.ts
    |- details
      |- details.component.ts | html
      |- details.module.ts
      |- details-routing.module.ts
  ...
<!-- src/app/features/home/home.component.html -->
<!-- src/app/features/home/home.component.html -->
// src/app/features/home/home.component.ts

import { Component } from '@angular/core'

@Component({
  moduleId: module.id,
  selector: 'ns-home',
  templateUrl: 'home.component.html'
})
export class HomeComponent {}

Source: link

Recent Questions on node.js

    Programming Languages