0

I have the following code in my html modal component:

<ng-container *ngFor="let school of schools">
   {{school.name}}
<ng-container>

However I'm getting the following error:

“Can't bind to 'ngForOf' since it isn't a known property of 'ng-container'

I've looked at other people's solutions online who suggest importing forms module, reactive forms module and common module, but I already have these imported in the modal module

import { FormsModule, ReactiveFormsModule } from "@angular/forms";
import { CommonModule } from "@angular/common";

Does anyone have any other suggestions on how I can get rid of this error?

NTP
  • 4,338
  • 3
  • 16
  • 24

2 Answers2

1

The ngFor directive is exported from the CommonModule, try importing the corresponding module to your app module imports or to the corresponding module in use.

FRANCISCO BERNAD
  • 473
  • 4
  • 15
  • 1
    Thanks @Francisco Bernad. But I already have the CommonModule imported in both my modal.module, and in my app.module files –  Aug 24 '21 at 18:49
0

Add BrowserModule in your app.module.ts. Stackblitz

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

@NgModule({
  imports:[ BrowserModule],

So, you should import BrowserModule in app.module whereas CommonModule in feature modules Here is a good read on this topic

amnah
  • 444
  • 2
  • 6