question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't bind to 'ngIf' since it isn't a known property of 'div'.

See original GitHub issue

Bug Report

Description using *ngIf in component template causes an error in browser console and no content is displayed.

Ionic Info

Ionic:

   ionic (Ionic CLI)          : 4.0.5 (/usr/local/lib/node_modules/ionic)
   Ionic Framework            : @ionic/angular 4.0.0-beta.1
   @angular-devkit/core       : 0.7.2
   @angular-devkit/schematics : 0.7.2
   @angular/cli               : 6.1.2
   @ionic/ng-toolkit          : 1.0.5
   @ionic/schematics-angular  : 1.0.4

Cordova:

   cordova (Cordova CLI) : 6.5.0
   Cordova Platforms     : browser 4.1.0

System:

   ios-deploy : 1.9.2
   ios-sim    : 5.0.13
   NodeJS     : v9.4.0 (/usr/local/lib/node_modules/node/bin/node)
   npm        : 6.0.1
   OS         : macOS Sierra
   Xcode      : Xcode 9.2 Build version 9C40b

Environment:

   ANDROID_HOME : not set

   Angular CLI: 6.1.2
   Node: 9.4.0
   OS: darwin x64
   Angular: 6.1.2

Related Code

  LocComponent is an @ionic/angular component 

  location is passed in
  @Input() location:any

  --- this mark up causes error in console and no content is displayed

 <div *ngIf="location.hour">
           {{location.hour}}
           {{location.day}}
           {{location.timezone}}
 </div>

 -- this mark up works
 <div>
           {{location.hour}}
           {{location.day}}
           {{location.timezone}}
 </div>


Expected Behavior

<div> should be displayed if condition is set, otherwise not displayed, according to the rules of angular.

Additional Context browser console trace: Template parse errors: Can't bind to 'ngIf' since it isn't a known property of 'div'. (" <span class="badge">2</span> <span class="badge">1</span> <div [ERROR ->]*ngIf="location && location.hour"> {{location.hour}} {{location.day}} "): ng:///ComponentsModule/LocComponent.html@7:15 Property binding ngIf not used by any directive on an embedded template. Make sure that the property name is spelled correctly and all directives are listed in the "@NgModule.declarations". (" <span class="badge">2</span> <span class="badge">1</span> [ERROR ->]<div *ngIf="location && location.hour"> {{location.hour}} {{location.day}} "):

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
grimacecommented, Aug 16, 2018

Yes, you are correct. I went through my code and discovered that the components.module.ts file did not have import { CommonModule } from '@angular/common'; it is now resolved. Thank you.

0reactions
ionitron-bot[bot]commented, Sep 15, 2018

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can't bind to 'ngIf' since it isn't a known property of 'div'
Can't bind to 'ngIf' since it isn't a known property of 'div '. The element is <div [ngIf]="isAuth" id="sidebar">. And the component is:...
Read more >
Can't bind to 'ngif' since it isn't a known property of 'div'
This error occurs when you are using a structural directive and trying to bind to a property that doesn't exist on the given...
Read more >
Angular Can't bind to 'ngIf' since it isn't a known property of 'div'
Solution for Angular Can't bind to 'ngIf' since it isn't a known property of 'div' ... There are multiple ways to fix this....
Read more >
How to solve this error Can't bind to 'ngIf' since it isn't a known ...
How to solve this error Can't bind to 'ngIf' since it isn't a known property of 'div'. Root module, child modules is fully...
Read more >
Can't bind to 'ngif' since it isn't a known property - Floyk
How to fix console error saying "Can't bind to 'ngif' since it isn't a known property" when working with Angular?...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found