Problem with ngFor

Asked

Viewed 103 times

-1

I updated my project to Angular 9 and my pages with ngFor and ngIf stopped working, appears:

core.js:12768 Can’t bind to 'ngForOf' Since it isn’t a known Property of 'div'.

As a browser error, in any tag I use the same error appears. I have already added the CommonModule so much on the app.module how much in the adddate.module and it still doesn’t work. Someone can help me?

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { HttpClientModule } from '@angular/common/http';
import { ModalModule, BsModalService, BsModalRef } from 'ngx-bootstrap/modal';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { AgendamentosComponent } from './agendamentos/agendamentos.component';
import { LoginComponent } from './login/login.component';
import { AlertModalComponent } from './alert-modal/alert-modal.component';
import { RegisterComponent } from './register/register.component';
import { AddDateComponent } from './add-date/add-date.component';
import { AddAgComponent } from './add-ag/add-ag.component';
import { SalasComponent } from './salas/salas.component';
import { Agendamentos12Component } from './agendamentos12/agendamentos12.component';
import { HeaderComponent } from './header/header.component';
import { AgendamentosNoiteComponent } from './agendamentos-noite/agendamentos-noite.component';
import { CommonModule } from "@angular/common";

@NgModule({
  declarations: [
    AppComponent,
    AgendamentosComponent,
    LoginComponent,
AddDateComponent,
    AlertModalComponent,
    RegisterComponent,
    AddAgComponent,
    SalasComponent,
    Agendamentos12Component,
    HeaderComponent,
    AgendamentosNoiteComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    HttpClientModule,
    CommonModule,
    BrowserAnimationsModule,
    ModalModule.forRoot()
  ],


  providers:[BsModalRef, BsModalService],
  bootstrap: [AppComponent]
})
export class AppModule { }

1 answer

1

If this is the root module of the project (AppModule), you must keep only the BrowserModule in the imports: [] of @NgModule().

If it is not the root module of the project, you keep only the CommonModule:

// Antes era da seguinte forma:
// import {BrowserModule, CommonModule} from '@angular/common';

// Agora é assim:
import { BrowserModule } from '@angular/platform-browser'
..
..
@NgModule({
  imports: [BrowserModule, /* ou CommonModule */],
  ..
})

Browser other questions tagged

You are not signed in. Login or sign up in order to post.