Angular Can';t绑定到';ngIf&x27;因为它不是';t'的已知属性;分区';生产中建造
我可以在本地运行。仅在生产生成中获取错误 我用过Angular Can';t绑定到';ngIf&x27;因为它不是';t'的已知属性;分区';生产中建造,angular,Angular,我可以在本地运行。仅在生产生成中获取错误 我用过 import { CommonModule } from '@angular/common'; imports: [ CommonModule ] 完整错误如下所示 client:101 Template parse errors:enter code here`Can't bind to 'ngIf' since it isn't a known property of 'div'. ("move" class="trans
import { CommonModule } from '@angular/common';
imports: [ CommonModule ]
完整错误如下所示
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
client:101模板解析错误:在此处输入代码`无法绑定到'ngIf',因为它不是'div'的已知属性。
(“移动”class=“运输移除”>移除
]*ngIf=“vehicleData.vesselType=”道路“>
"): VehicleDirective@10:52
属性绑定ngIf未被嵌入模板上的任何指令使用。请确保属性名称拼写正确,并且所有指令都列在“@NgModule.declarations”中(“t:”(单击)=“removeField($event)”title=“Remove”class=“transport Remove”>Remove
[错误->]
]*ngFor=“让车辆制造.makes”>{{make}
"): VehicleDirective@28:26
嵌入模板上的任何指令都不使用属性绑定。确保属性名称拼写正确,并且所有指令都列在“@NgModule.declarations”中。(“[(ngModel)]=“vehicleData.makeSelect”(更改)=“appendModel($event.target.value)”>
[错误->]{make}
[错误->]{{model}
"): VehicleDirective@36:15
无法绑定到“ngForOf”,因为它不是“option”的已知属性。(“Xbox”>
挑选
]*ngFor=“出租车辆年份.years”>{{year}
"): VehicleDirective@47:32
嵌入模板上的任何指令都不使用属性绑定ngForOf。请确保属性名称拼写正确,并且所有指令都列在“@NgModule.declarations”中(“class=”prefixbox“>
挑选
[错误->]{year}
"): VehicleDirective@47:24
无法绑定到“ngForOf”,因为它不是“option”的已知属性(“ateSelect”[(ngModel)]=“vehicleData.stateSelect”class=“prefixbox”>
]*ngFor=“let state of vehicle.regStates”>{{state}
"): VehicleDirective@55:32
嵌入模板上的任何指令都不使用属性绑定。确保属性名称拼写正确,并且所有指令都列在“@NgModule.declarations”中。(“id=”stateSelect“[(ngModel)]=”vehicleData.stateSelect“class=”prefixbox“>
[错误->]{{state}
"): VehicleDirective@55:24
无法绑定到“ngForOf”,因为它不是“option”的已知属性(“lorSelect”[(ngModel)]=“vehicleData.colorSelect”class=“prefixbox”>
]*ngFor=“let color of vehicle.colors”>{{color}
"): VehicleDirective@68:32
嵌入模板上的任何指令都不使用属性绑定。确保属性名称拼写正确,并且所有指令都列在“@NgModule.declarations”中。(“id=”colorSelect“[(ngModel)]=”vehicleData.colorSelect“class=”prefixbox“>
[错误->]{{color}
"): VehicleDirective@68:24
原因是什么。我已经验证了许多解决方案。找不到解决方案。相同的代码在本地运行正常。添加浏览器模块后,其工作正常
import { BrowserModule } from '@angular/platform-browser';
@NgModule({
imports: [BrowserModule ]
})
您应该在根组件或相关组件中添加CommonModule
从“@angular/common”导入{CommonModule};
另外,将CommonModule
添加到@NgModule的imports
属性中,并将组件添加到declarations
属性中
@NgModule({
声明:[
应用组件
],
进口:[
公共模块
],
提供者:[],
引导:[AppComponent]
})
我遇到了完全相同的错误,我包括了CommonModule和BrowserModule,但我仍然在浏览器上看到了相同的错误消息
最后,我发现问题的原因是我忘记将我的组件添加到app.module.ts,以防其他人处理相同的行为。如果模块的
声明中未包含您的组件,也可能发生此错误:
从'@angular/core'导入{NgModule};
从“@angular/common”导入{CommonModule};//如果以上方法都不起作用,那么其他解决方案就是重新启动对我有效的ng SERVICE
。或者在拔出头发之前先尝试此方法
PS:这不是OP的问题,因为他正在生产中,这只是用于开发环境。在div元素上使用ngIf的地方添加HTML模板代码这是否回答了您的问题?看起来Angular的错误处理可能“知道”(或猜测)ngIf是它自己的指令之一,并且“知道”它在BrowserModule中。浏览器控制台中的错误消息可能会提示“是否已导入BrowserModule”?Angular IMHO中最大的缺点可能是出错时错误消息没有多大帮助。这对我很有效!非常感谢您提到这一点!!!Ca我不相信这不是一个更被接受的答案。顺便说一句,如果你想知道在哪里,它应该在导入中:导入:[……,modalpage模块],错误消息太糟糕了,我们应该如何找到这个lol。谢谢!我认为这是最好的答案。谢谢,伙计!在浏览了所有帖子之后。最后阅读了这篇评论,我觉得没有检查app.modules.ts很傻。谢谢你的回答谢谢-这对我很有效,我遇到了这个问题,在重新启动ng serve
!我也是。我将表单控件移动到另一个组件中,并启动了g