angular-cli - ng 在子目录中生成组件

标签 angular-cli angular5 ng-generate

我有以下目录结构

enter image description here

我想创建一个新页面,比如说一个关于页面。
我想把它放在 src/app/page/about/*

所以我尝试:

ng generate component pages/about

但我收到此错误:
Error: More than one module matches. Use skip-import option to skip importing the component into the closest module.
More than one module matches. Use skip-import option to skip importing the component into the closest module.

使用页面来存储我的单独页面是个好主意吗?
如何使用 angular-cli 在子目录中生成组件?

最佳答案

因为有 2 个模块(app.module.tsshared.module.ts)发现 CLI 不知道在哪个模块中声明您的组件。要解决这个问题,您必须使用 module 选项告诉 CLI 您希望在哪个模块中声明您的组件

ng generate component pages/about --module=app.module
// or
ng generate component pages/about --module=shared.module

关于angular-cli - ng 在子目录中生成组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48102863/

相关文章:

html - 为什么我不能用angular-cli上传我的本 map 片?

javascript - 如何使用 Angular 中其他 http 服务的输出来调用组件中的 http get 服务?

angular - 使用 HttpInterceptor 添加加载屏幕

Angular 5 HttpClient GET : SUCCESSFUL if in constructor FAILS when ngOnInit

java - 如何将 Angular 与 Spring Boot 集成以在 Spring Boot 端口上查看 Angular Web 界面?

Angular 2 + CLI : Error in Maximum call stack size exceeded

angular-cli - npm 在安装 Angular CLI 时抛出 EACCES 错误