今天在angular中执行 ng g c componentName 时,出现More than one module matches. Use skip-import option to skip importing the component into the closes的报错信息,下面主要说一下产生原因及解决方法。
- 产生原因:
在该工程下,有两个module文件,我在该项目下有一个app.module.ts文件和huatuo.module.ts两个module文件,在创建组件时,由于不知道往那个module中添加新创建的组件信息而导致的报错。
- 解决方法:
创建组件时,指定module文件:
ng g c componentName --module=app.module(往app.module.ts中添加创建的组件信息)
ng g c componentName --module=huatuo.module(往huatuo.module.ts中添加创建的组件信息)