I have already taken a look at this question which had a lot of answers (all the same) but it could not fix my problem.
Let me quickly lay out my project structure
@NgModule({
declarations: [AppComponent],
imports: [AppRoutingModule, GlobalModule],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule {}
const routes: Routes = [
{
path: 'Session',
loadChildren: () => import('./session/session-routing.module').then((m) => m.SessionRoutingModule)
}
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule {}
I have a fairly new project and I employ lazy loading routes. The session routing module is defined as following
const routes: Routes = [{ path: 'Login', component: LoginComponent }];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule]
})
export class SessionRoutingModule {}
and my LoginComponent is declared in the SessionModule
@NgModule({
declarations: [LoginComponent],
imports: [GlobalModule]
})
export class SessionModule {}
You can see that both the SessionModule
and the AppModule
import the GlobalModule
. This is a module I made to import everywhere since it will export a lot of stuff which will be used practically everywhere.
@NgModule({
declarations: [],
exports: [CommonModule, FormsModule, ReactiveFormsModule, MaterialComponentsModule, PipesModule, BrowserModule, PlatformModule]
})
export class GlobalModule {}
That's all there is to the modules. Now for the loginComponent
's HTML
<form [formGroup]="form" (ngSubmit)="submit()" class="vh-100 gradient-custom"></form>
This will throw the error
Error: src/app/session/login/login.component.html:1:7 - error NG8002: Can't bind to 'formGroup' since it isn't a known property of 'form'.
All answers I could find is 'You need to import the ReactiveFormsModule'. But I definitely do that by importing the globalModule which exports those. I also simply out of frustation added those to my SessionModule
@NgModule({
declarations: [LoginComponent],
imports: [GlobalModule, FormsModule, ReactiveFormsModule]
})
export class SessionModule {}
But still the same error. And I cannot find where it comes from. The LoginComponent
is declared in the same module that imports those FormModules. Has it something to do with routing? What am I missing? I already tried a lot of combinations for my imports.
EDIT:
Even VsCode can find the documentation of the directive when I ctrl+click
on it
Error screenshot below