角导入app.module vs child.module中的FormsModule [英] Angular importing FormsModule in app.module vs child.module

查看:170
本文介绍了角导入app.module vs child.module中的FormsModule的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将Angular与延迟加载模块一起使用.每个组件都有其自己的模块.如果我在根模块(app.module)中导入模块,则它必须可以正常工作.例如,我在app.module中导入了HttpClientModule并可以在子组件中使用它.

I'm using Angular with lazy loading modules. Each component has its own module. If I import a module in the root module (app.module) it must work fine. For example, I imported HttpClientModule in app.module and can use it in child components.

但是关于FormsModule,这不能正常工作.我必须将其导入子模块中,否则会出现以下错误:

But about FormsModule, this doesn't work fine. I must import it in the child module, otherwise, I get the following errors:

Can't bind to 'ngModel' since it isn't a known property of 'input'. ("

推荐答案

我找到了答案

  • 如果模块是为组件导入的,则需要将其导入需要它们的每个模块中,
  • 如果该模块是为服务导入的,则只需在第一个应用程序模块中将其导入一次.
  • 这篇关于角导入app.module vs child.module中的FormsModule的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆