ng 在子目录中生成组件 [英] ng generate component in subdirectory

查看:47
本文介绍了ng 在子目录中生成组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下目录结构

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

I would like to create a new page, let's say, an About page. I want to put it in 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 在子目录中生成组件?

Is it a good idea to use pages to store my separate pages? How can I generate components in a subdirectory using the angular-cli?

推荐答案

因为找到了 2 个模块 (app.module.ts, shared.module.ts)CLI 不知道要在哪个模块中声明您的组件.要解决此问题,您必须告诉 CLI 您希望使用 module 选项

Because there are 2 modules (app.module.ts, shared.module.ts) found the CLI does not know which module to declare your component in. To get around this you have to tell the CLI which module you wish to declare your component in with the module option

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

这篇关于ng 在子目录中生成组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆