user user - 1 year ago 82
TypeScript Question

How make ngIf directive globally visible in all project?

I have a code

<div class="flex-container" *ngIf="mail"> Some data </div>

And i have a error
Can't bind to 'ngIf' since it isn't a known property of 'div'.

How i can fix it?

Answer Source

Import BrowserModule in the root module and CommonModule in other modules where you want to use common directives.

  imports: [BrowserModule],
class AppModule {}


  imports: [CommonModule],
  // Now MyComponent has access to ngIf
  declarations: [MyComponent]
class OtherModule {}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download