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

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

问题描述

我具有以下目录结构

我想创建一个新页面,例如About页面. 我想把它放在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.tsshared.module.ts),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天全站免登陆