Angular2: Error – Can’t bind to ‘ngForOf’ since it isn’t a known property

Standard

While displaying data from web-api in html code, I used *ngFor, which is a repeater directive — a way to customize data display.

2016-10-28-16_40_42-speechimdb-microsoft-visual-studio

I came across below issue: 

EXCEPTION: Unhandled Promise rejection: Template parse errors:
Can’t bind to ‘ngForOf’ since it isn’t a known property of ‘li’.
Property binding ngForOf not used by any directive on an embedded template. Make sure that the property name is spelled correctly and all directives are listed in the “directives” section

 

2016-10-28-16_37_01-home-page-my-asp-net-application

Solution:

You should import the BrowserModule in your app module and import CommonModule in children modules. You should only import BrowserModule once. Other modules should be importing CommonModules instead.

Children Module(Dashboard):

import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { CommonModule } from '@angular/common';

import { DashboardComponent } from './dashboard.component';

@NgModule({
 imports: [
     FormsModule,
     CommonModule
   ],
 declarations: [
     DashboardComponent
   ]
})

export class DashboardMainModule {
}

Main Module:

import { NgModule} from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';

import { DashboardMainModule } from './dashboard/dashboard.module';
import { AppComponent } from './app.component';

@NgModule({
 imports: [
    BrowserModule,
    DashboardMainModule
  ],
 declarations: [
    AppComponent
  ],
 bootstrap: [
    AppComponent
  ]
})

export class AppModule {
}

Advertisements

5 thoughts on “Angular2: Error – Can’t bind to ‘ngForOf’ since it isn’t a known property

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s