Error using ngFor at angular: Can’t bind to 'ngForOf' Since it isn’t a known Property of 'tr'

Asked

Viewed 224 times

1

I am getting the following error when using ngFor directive at the angle: Can’t bind to 'ngForOf' Since it isn’t a known Property of 'tr'.

This is my code:

usuario.componentts.

import { Component, OnInit } from '@angular/core';
import { Usuario } from '../usuario';
import { UsuarioService } from '../usuario.service';

@Component({
  selector: 'app-usuario',
  templateUrl: './usuario.component.html',
  styleUrls: ['./usuario.component.scss']
})
export class UsuarioComponent implements OnInit {
  public usuarios: Usuario[] = [
    {
      nome: "João Filipe",
      email: "[email protected]"
    },
    {
      nome: "Jesiel",
      email: "[email protected]"
    },
    {
      nome: "Jamile",
      email: "[email protected]"
    },
    {
      nome: "Jéssica",
      email: "[email protected]"
    }
  ]
  constructor(private usuarioService: UsuarioService) { }

  ngOnInit(): void {
  }

}

usuario.modulets.

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

@NgModule({
  declarations: [],
  imports: [
    CommonModule
  ]
})
export class UsuarioModule { }

usuario.component.html

<table>
    <tr>
        <th>
            Nome
        </th>
        <th>
            E-mail
        </th>
    </tr>
    <tr *ngFor="let usuario of usuarios;">
        <td>{{usuario.nome}}</td>
        <td>{{usuario.email}}</td>
    </tr>
</table>

app.modulets.

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { MenuComponent } from './menu/menu.component';
import { FooterComponent } from './footer/footer.component';

@NgModule({
  declarations: [
    AppComponent,
    MenuComponent,
    FooterComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

  • ngForOf but is using ngFor

  • What do you mean? I’m new to Angular, I don’t quite understand.

  • In the html you posted is using ngFor and the error you showed is indicating the use of ngForOf.

  • I know. But I’m only using ngFor. And even then, the error persists.

  • When I remove ngFor, the error goes away. This is the proof that is attached to ngFor.

  • Strange guy pq this error occurs when the Commonmodule is not used in the module that is using ngFor, which is not the case there. I really don’t know why the bug!

  • The app.module.ts and user.module.ts are correct so it should be working. Try to delete the node_modules folder then gives an npm install and an ng serves to see if the error still persists.

  • @brenodiogo, I just did, the error still persists. :/

  • your app.module.ts is correct? There in the declarations do not have the Usuariocomponent, so the angular should not even be compiling

Show 4 more comments
No answers

Browser other questions tagged

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