gpt4 book ai didi

Angular 在 app.module 和 child.module 中导入 FormsModule

转载 作者:行者123 更新时间:2023-12-04 02:51:05 28 4
gpt4 key购买 nike

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

但是关于 FormsModule,这并不能很好地工作。我必须在子模块中导入它,否则会出现以下错误:

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

你知道为什么会这样吗?

最佳答案

我找到了答案 here :

  • 如果模块是为组件导入的,则需要在每个需要它们的模块中导入它,
  • 如果模块是为服务导入的,您只需在第一个应用模块中导入一次。

关于Angular 在 app.module 和 child.module 中导入 FormsModule,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54957210/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com