我怎样才能在这个文件夹中创建一个 Angular 全新的组件?为什么我使用 Angular CLI 会收到此错误消息?
How can I create an Angular brand new component into this folder? Why am I obtaining this error message using Angular CLI?
我是 Angular 的绝对初学者,我发现在使用 Angular CLI 将组件创建到我正在处理的 Angular 项目中时遇到了一些问题。
我手动创建了一个子文件夹(进入我的 Angular 项目),我想在其中创建我的新组件,例如:
C:\Users\myusre\Source\Workspaces\MySolution\MyProject\WebProject\app\maildetail\maildetail-sidebar
我将此文件夹访问到我的 shell 中并执行此语句:
ng generate component main-detail-protocollo-sidebar
所以我希望为我的新组件获取一个新目录(到以前的目录)。
但我收到此错误消息:
The generate command requires to be run in an Angular project, but a project definition could not be found.
为什么?怎么了?我错过了什么?如何直接在之前的文件夹中创建一个全新的组件?
您应该进入包含您的 angular.json
的文件夹
从那里你可以在组件名称中指定子路径,就像这样:
ng generate component subfolder/main-detail-protocollo-sidebar
您必须在项目文件夹中 angular.json
或 angular-cli.json
并尝试 运行 生成命令
ng generate component folder/main-detail-protocollo-sidebar --flat
通常cli
会在你运行generate
命令时生成一个文件夹,避免你可以使用--flat
希望这对您有所帮助 - 编码愉快:)
我是 Angular 的绝对初学者,我发现在使用 Angular CLI 将组件创建到我正在处理的 Angular 项目中时遇到了一些问题。
我手动创建了一个子文件夹(进入我的 Angular 项目),我想在其中创建我的新组件,例如:
C:\Users\myusre\Source\Workspaces\MySolution\MyProject\WebProject\app\maildetail\maildetail-sidebar
我将此文件夹访问到我的 shell 中并执行此语句:
ng generate component main-detail-protocollo-sidebar
所以我希望为我的新组件获取一个新目录(到以前的目录)。
但我收到此错误消息:
The generate command requires to be run in an Angular project, but a project definition could not be found.
为什么?怎么了?我错过了什么?如何直接在之前的文件夹中创建一个全新的组件?
您应该进入包含您的 angular.json
的文件夹从那里你可以在组件名称中指定子路径,就像这样:
ng generate component subfolder/main-detail-protocollo-sidebar
您必须在项目文件夹中 angular.json
或 angular-cli.json
并尝试 运行 生成命令
ng generate component folder/main-detail-protocollo-sidebar --flat
通常cli
会在你运行generate
命令时生成一个文件夹,避免你可以使用--flat
希望这对您有所帮助 - 编码愉快:)