I\'m using Angular2 Final release (2.1.0). When I want to display a list of companies, I got this error.
in file.component.ts
:
public
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]
})
In my case, the 2nd method solved my issue.
Hope this will help you