由于缺少 app.module.ts 文件,在 Ionic Angular 7 项目中无法使用响应式表单。

huangapple go评论118阅读模式
英文:

Unable to use reactive forms in Ionic Angular 7 project due to missing app.module.ts file

问题

我正在开发一个 Ionic Angular 7 项目,尝试在我的应用程序中使用响应式表单。由于 Ionic Angular 7 中移除了 app.module.ts,我尝试查阅了一些在互联网上找到的文章。然而,当我尝试在我的 main.ts 文件中导入 ReactiveFormsModule,就像那些文章中提到的那样,它并没有起作用。

在导入了 ReactiveFormsModule 后 main.ts 文件中的代码示例:

bootstrapApplication(AppComponent, {
  providers: [
    { provide: RouteReuseStrategy, useClass: IonicRouteStrategy },
    importProvidersFrom(IonicModule.forRoot({}),ReactiveFormsModule),
    provideRouter(routes),
  ],
});

我不确定如何在我的 Ionic Angular 7 项目中继续使用响应式表单。我应该如何将 ReactiveFormsModule 添加到我的项目中并使用响应式表单?

英文:

I'm working on an Ionic Angular 7 project and I'm trying to use reactive forms in my application. As app.module.ts is removed from Ionic Angular 7, I tried to check through few articles found on Internet. However, when I try to import the ReactiveFormsModule in my main.ts file as mentioned in those articles, it didn't work.

Sample of code from main.ts after importing ReactiveFormsModule:

bootstrapApplication(AppComponent, {
  providers: [
    { provide: RouteReuseStrategy, useClass: IonicRouteStrategy },
    importProvidersFrom(IonicModule.forRoot({}),ReactiveFormsModule),
    provideRouter(routes),
  ],
});

I'm not sure how to proceed with using reactive forms in my Ionic Angular 7 project. How can I add the ReactiveFormsModule to my project and use reactive forms?

答案1

得分: 1

在使用该组件时,您需要在其中导入它:

@Component({
  standalone:true,
  imports: [ReactiveFormsModule]
})
英文:

You need to import it in the component it's being used in:

@Component({
  standalone:true,
  imports: [ReactiveFormsModule]
})

huangapple
  • 本文由 发表于 2023年4月7日 02:05:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/75952491.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定