当我尝试在angular cli中创建一个组件时,它显示了这个错误。我怎样才能摆脱它呢?

错误:多个模块匹配。使用skip-import选项可以跳过将组件导入到最近的模块。

我使用的是angular cli版本:1.4.1


当前回答

如果您在特定的模块中创建,请进入该路径并运行 Ng g c组件名

否则先创建模块 模块名称

cd / app / modulename弧 进入modulename path并创建组件

其他回答

在我的例子中,ng似乎没有注册到我的环境路径中。我一直使用npm run命令来运行ng命令。注意,为了传递参数,你需要一个额外的参数——根据npm运行规范。

例子:

npm run ng g c components/scheduling **--** --module=app

Or:

npm run ng g c components/scheduling **--** --skip-import

当有多个模块时,需要指定模块名

 ng g c componentName --module=modulename.module 

对我来说,这个命令工作:

ng g c new-component --module app

试试ng g component header——module app 这是我的工作

Angular CLI: 8.3.1

当你有多个模块时。Ts文件,您需要指定为哪个模块文件生成组件。

ng g c modulefolder/componentname --module=modulename.module

例如,我有一个共享模块文件夹,里面有共享的.module.ts和material.module.ts,就像这样

shared
  > shared.module.ts
  > material.module.ts

我想为shared.module.ts生成侧边栏组件 然后我将运行以下命令

ng g c shared/sidebar --module=shared.module

如果要导出组件,则运行以下命令

ng g c shared/sidebar --module=shared.module --export