Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular2 compiler-cli not recognizing [ngClass] or *ngIf

Tags:

angular

I want to compile ahead-of-time using the latest version Angular's offline compiler. I updated all the necessary packages to RC5, have the latest version of the compiler, etc.

But then I got a bunch of errors such as:

  • Can't bind to 'ng-class' since it isn't a known property of 'div'.
  • Can't bind to 'ngIf' since it isn't a known property of 'div'.
  • 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 "directives" section.
  • Can't bind to 'ngClass' since it isn't a known property of 'my-component'.

I noticed from http://www.syntaxsuccess.com/viewarticle/offline-compilation-in-angular-2.0 that it may be necessary to include common directives in the @Component decorator. But it looks like this has been fixed since RC5: https://github.com/angular/angular/blob/master/CHANGELOG.md. And the error I'm getting when I try this seems to suggest this is no longer necessary:

Type NgIf is part of the declarations of 2 modules: CommonModule and AppModule!

I can also compile and run the site normally using tsc and RC5, so it isn't an upgrading issue. So I'm totally at a loss as to what may be causing these errors.

Any help is much appreciated.

like image 960
Brendan B Avatar asked Feb 16 '26 14:02

Brendan B


1 Answers

The solution was very trivial. I was just missing BrowserModule from the @NgModule imports in AppModule.

like image 52
Brendan B Avatar answered Feb 19 '26 05:02

Brendan B



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!