当我尝试在angular cli中创建一个组件时,它显示了这个错误。我怎样才能摆脱它呢?
错误:多个模块匹配。使用skip-import选项可以跳过将组件导入到最近的模块。
我使用的是angular cli版本:1.4.1
当我尝试在angular cli中创建一个组件时,它显示了这个错误。我怎样才能摆脱它呢?
错误:多个模块匹配。使用skip-import选项可以跳过将组件导入到最近的模块。
我使用的是angular cli版本:1.4.1
当前回答
有两种方法可以解决这个问题。
1)跳过(在命令中使用——Skip -import)默认导入并创建组件,一旦组件创建完成,就可以手动将它导入到任何你想使用它的地方。
ng generate component my-component --skip-import
2)在你想导入模块的地方显式地提供模块名
ng generate component my-component --module=my-module.module
其他回答
试试ng g component header——module app 这是我的工作
作为一个黑客,下面的步骤,对我有用。
1)移动*.module。Ts文件从src/app到项目外的位置。
2)执行命令创建组件[ng g c component-name]
3)移回*.模块。Ts文件到src/app/
你必须在.module扩展名之前只提到模块的起始名
例如,如果模块名是user-account.module.ts 然后在命令中提供喜欢
ng g c newComponent --module=user-account
当app文件夹下有多个模块时,使用以下命令生成组件将失败:
ng generate component New-Component-Name
原因是angular CLI检测到多个模块,不知道该在哪个模块中添加组件。因此,您需要显式地提到将添加哪个模块组件:
ng generate component New-Component-Name --module=ModuleName
当有多个模块时,需要指定模块名
ng g c componentName --module=modulename.module