I was getting the same error,
You can fix through one of this method:
If you don't have any nested module
a. Import the CommonModule in your App module
b. Import your Component where you are adding the *ngFor in the App Module, define in declarations
// file App.modules.ts
@NgModule({
declarations: [
LoginComponent // declarations of your component
],
imports: [
BrowserModule
DemoMaterialModule,
FormsModule,
HttpClientModule,
ReactiveFormsModule,
AppRoutingModule,
BrowserAnimationsModule,
ServiceWorkerModule.register('ngsw-worker.js', { enabled: environment.production })
],
providers: [
ApiService,
CookieService,
{
provide: HTTP_INTERCEPTORS,
useClass: ApiInterceptor,
multi: true
}
],
bootstrap: [AppComponent]
})
c. If you are using the separate module file for routing then Import the CommonModule in your Routing module else Import the CommonModule in your App module
// file app.routing.modules.ts
import { LoginComponent } from './login/login.component';
import { CommonModule } from "@angular/common";
const routes: Routes = [
{ path: '', component: LoginComponent },
{ path: 'login', component: LoginComponent }
];
@NgModule({
imports: [RouterModule,RouterModule.forRoot(routes), CommonModule],
exports: [RouterModule]
})
- If you have nested module then perform the 1st step in that particular module
In my case, the 2nd method solved my issue.
Hope this will help you
ngfor
gives the error you mentioned. Should bengFor
– Piotr Kula