当我尝试在angular cli中创建一个组件时,它显示了这个错误。我怎样才能摆脱它呢?
错误:多个模块匹配。使用skip-import选项可以跳过将组件导入到最近的模块。
我使用的是angular cli版本:1.4.1
当我尝试在angular cli中创建一个组件时,它显示了这个错误。我怎样才能摆脱它呢?
错误:多个模块匹配。使用skip-import选项可以跳过将组件导入到最近的模块。
我使用的是angular cli版本:1.4.1
当前回答
试试这个:它对我很有效
生成组件componentName——module=app.module
其他回答
当我试图在一个文件夹下创建一个新组件时,我正在得到下面的错误。
错误:多个模块匹配。使用skip-import选项可以跳过将组件导入到最近的模块。
我已经使用下面的命令和新组件成功创建在一个文件夹下。
ng g c folderName/my_newComponent ---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
使用——module参数指定模块。 例如,如果主模块是app.module。Ts,运行这个:
ng g c new-component --module app
或者如果你在另一个目录
ng g c component-name --module ../
我有这个警告时,有这个角。json配置:
"prefix": "app_ng"
当更改为“app”时,一切都工作得很好。
当app或lib有多个嵌套模块时
myApp
> src
> app
app.module.ts
> routes
> login
> auth
login.module.ts
角CLI
ng g component routes/login/auth/my-auth --module=routes/login/login.module.ts
NRWL NX Angular CLI
ng g component routes/login/auth/my-auth --project=myApp --module=routes/login/login.module.ts
结果
myApp
> src
> app
app.module.ts
> routes
> login
> auth
> my-auth
my-auth.component.ts etc...
login.module.ts