Can't bind to 'ngIf' since it isn't a known property of 'div' in production build

前端 未结 5 1138
离开以前
离开以前 2021-01-13 03:11

I can able to run through locally. Getting error only in production build.

I have used

 import { CommonModule } from \'@angular/common\';
 imports:           


        
相关标签:
5条回答
  • 2021-01-13 03:13

    You should add CommonModule either in the root component or the related component,

    import { CommonModule } from "@angular/common";
    

    Also, add CommonModule to the imports property of @NgModule and your component to the declarations property.

    @NgModule({
      declarations: [
        AppComponent
      ],
      imports: [
        CommonModule
      ],
      providers: [],
        bootstrap: [AppComponent]
      })
    
    0 讨论(0)
  • 2021-01-13 03:20

    Other solution if none of the above works is just to restart your ng serve, that worked for me. Or maybe try this method first before pulling your hairs out.

    0 讨论(0)
  • 2021-01-13 03:23

    After adding browser module its working fine.

     import { BrowserModule } from '@angular/platform-browser';
     @NgModule({
         imports: [BrowserModule ]
      })
    
    0 讨论(0)
  • 2021-01-13 03:28

    I had exactly the same error, and I had included both CommonModule and BrowserModule and yet I still saw the same error message on my browser.

    Finally, I found the cause of my problem was that I forgot to add my component to app.module.ts, in case someone else is dealing with the same behavior.

    0 讨论(0)
  • 2021-01-13 03:35

    This error can also occur if your component is NOT included in the declarations section of the module:

    import { NgModule } from '@angular/core';
    import { CommonModule } from '@angular/common';            // <-- required
    
    import { InventoryRoutingModule } from './inventory-routing.module';
    import { InventoryComponent } from './pages/inventory/inventory.component';
    
    @NgModule({
      declarations: [InventoryComponent],                      // <-- In my case, this was missing
      imports: [CommonModule, InventoryRoutingModule]
    })
    export class InventoryModule {}
    
    0 讨论(0)
提交回复
热议问题