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

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

我使用的是angular cli版本:1.4.1


当前回答

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

ng g c new-component --module app

其他回答

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

 ng g c componentName --module=modulename.module 

这是由于生成试图将您的组件添加到模块,即添加这一行

import { MyComponent } from './Components/my-component/my-component.component';

但它找到了两个模块。

正如这里所述,他们修复了一种情况,只要在根src/app文件夹中只有一个模块,就可以了,所以只需将辅助模块移动到子文件夹中。

否则你必须使用——module

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

ng g c new-component --module app

这对我很有用

ng g component component-name --skip-import

当我试图在一个文件夹下创建一个新组件时,我正在得到下面的错误。

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

我已经使用下面的命令和新组件成功创建在一个文件夹下。

 ng g c folderName/my_newComponent ---module ../app