Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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

I have used

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

Full error is shown below.

client:101 Template parse errors:enter code here`Can't bind to 'ngIf' since it isn't a known property of 'div'.  ("move" class="transport-remove">Remove</a></div>          <div id="carTypeDiv_1" class="veh-inv-out" [ERROR ->]*ngIf="vehicleData.vesselType == 'road'">             <ul id="carTypeList_1" class="veh-slides">     "): VehicleDirective@10:52 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". ("t:" (click)="removeField($event)" title="Remove" class="transport-remove">Remove</a></div>          [ERROR ->]<div id="carTypeDiv_1" class="veh-inv-out" *ngIf="vehicleData.vesselType == 'road'">             <ul "): VehicleDirective@10:9 Can't bind to 'ngForOf' since it isn't a known property of 'option'. ("l)]="vehicleData.makeSelect" (change)="appendModel($event.target.value)">                   <option [ERROR ->]*ngFor="let make of vehicle.makes">{{make}}</option>                </select>             </div> "): VehicleDirective@28:26 Property binding ngForOf 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". ("[(ngModel)]="vehicleData.makeSelect" (change)="appendModel($event.target.value)">                   [ERROR ->]<option *ngFor="let make of vehicle.makes">{{make}}</option>                </select>             </d"): VehicleDirective@28:18 Can't bind to 'ngForOf' since it isn't a known property of 'option'. ("t" id="modelSelect" [(ngModel)]="vehicleData.modelSelect" class="prefixbox">                <option [ERROR ->]*ngFor="let model of vehicle.models">{{model}}</option>             </select></div>             <br c"): VehicleDirective@36:23 Property binding ngForOf 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". ("delSelect" id="modelSelect" [(ngModel)]="vehicleData.modelSelect" class="prefixbox">                [ERROR ->]<option *ngFor="let model of vehicle.models">{{model}}</option>             </select></div>          "): VehicleDirective@36:15 Can't bind to 'ngForOf' since it isn't a known property of 'option'. ("refixbox">                         <option value="">SELECT</option>                         <option [ERROR ->]*ngFor="let year of vehicle.years">{{year}}</option>                      </select>                  "): VehicleDirective@47:32 Property binding ngForOf 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". ("class="prefixbox">                         <option value="">SELECT</option>                         [ERROR ->]<option *ngFor="let year of vehicle.years">{{year}}</option>                      </select>          "): VehicleDirective@47:24 Can't bind to 'ngForOf' since it isn't a known property of 'option'. ("ateSelect" [(ngModel)]="vehicleData.stateSelect" class="prefixbox">                         <option [ERROR ->]*ngFor="let state of vehicle.regStates">{{state}}</option>                      </select>            "): VehicleDirective@55:32 Property binding ngForOf 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". ("" id="stateSelect" [(ngModel)]="vehicleData.stateSelect" class="prefixbox">                         [ERROR ->]<option *ngFor="let state of vehicle.regStates">{{state}}</option>                      </select>    "): VehicleDirective@55:24 Can't bind to 'ngForOf' since it isn't a known property of 'option'. ("lorSelect" [(ngModel)]="vehicleData.colorSelect" class="prefixbox">                         <option [ERROR ->]*ngFor="let color of vehicle.colors">{{color}}</option>                      </select>               "): VehicleDirective@68:32 Property binding ngForOf 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". ("" id="colorSelect" [(ngModel)]="vehicleData.colorSelect" class="prefixbox">                         [ERROR ->]<option *ngFor="let color of vehicle.colors">{{color}}</option>                      </select>       "): VehicleDirective@68:24 

What is the reason. I have verified many solution. could not find the soultion. Same code is working fine with local.

like image 860
raj m Avatar asked Feb 06 '17 08:02

raj m


People also ask

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

Solution for Angular Can't bind to 'ngIf' since it isn't a known property of 'div' There are multiple ways to fix this. Incorrect ngIf syntax One way, This is due to an error caused due to misspelling capital 'I' for div. To solve this, Import CommonModule or BroswerModule or both into app.

Can't bind to ngForOf since it isn't a known property of TR?

Error: NG0303: Can't bind to 'ngForOf' since it isn't a known property of 'ion-item'. Explanation: This error occurs when you use ngIf/ ngFor in the component, where you have not imported CommonModule. Fix: To fix this you have to import the CommonModule in the module file which is used by that HTML file.

How do I write in ngIf?

NgIf is a directive that is used to add an element subtree to the DOM on the basis of true value of an expression. If the value of expression is false then the element subtree will be removed from the DOM. To use NgIf we need to prefix it with asterisk (*) as *ngIf .


2 Answers

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.

like image 186
jmanz Avatar answered Oct 15 '22 08:10

jmanz


After adding browser module its working fine.

 import { BrowserModule } from '@angular/platform-browser';  @NgModule({      imports: [BrowserModule ]   }) 
like image 23
raj m Avatar answered Oct 15 '22 06:10

raj m