[英]How to generate a component in Nativescript 8 and angular
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 .我只是安装了所有要求,并按照https://nativescript.org上的指南为 Nativescript 8 开发设置了带有 Apple Silicon M1 芯片的新 Mac。 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:这要求输入名称和您想要的口味,我选择 Angular。现在我想开始创建新组件,但是在尝试运行以下命令时:
ng g c my-component
I get the following error:我收到以下错误:
The generate command requires to be run in an Angular project, but a project definition could not be found. generate 命令需要在 Angular 项目中运行,但是找不到项目定义。
I already have the angular cli installed (version 12 latest) globally.我已经在全球范围内安装了 angular cli(最新版本 12)。 What command should I run to create components or other stuff like services or modules;我应该运行什么命令来创建组件或其他东西,如服务或模块; or do I need another package to do so.还是我需要另一个 package 才能这样做。
You're missing angular.json
in your project.您在项目中缺少angular.json
。 And did you already install NativeScript Schematics?您是否已经安装了 NativeScript 原理图? ( npm i --save-dev @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.将my-project-name
替换为您的项目名称,然后再次运行 generate 命令。
I use Add Angular Native Files with Visual Studio code.我将 Add Angular Native Files 与 Visual Studio 代码一起使用。 Pretty much works like ng g c componentName.几乎像 ng g c componentName 一样工作。 You will just need to add the component to app.module.ts您只需要将组件添加到 app.module.ts
More info here:更多信息在这里:
https://marketplace.visualstudio.com/items?itemName=joshdsommer.vscode-add-angular-native-files https://marketplace.visualstudio.com/items?itemName=joshdsommer.vscode-add-angular-native-files
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.