在生产构建中,无法将'ngIf'绑定到'div',因为它不是已知的'属性'.

11 浏览
0 Comments

在生产构建中,无法将'ngIf'绑定到'div',因为它不是已知的'属性'.

我在本地运行时没有问题,只有在生产版本出错。

我使用了

 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
         ]*ngIf="vehicleData.vesselType == 'road'">
    • "): 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 [ERROR ->] <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)">]*ngFor="let make of vehicle.makes">{{make}} "): 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 ->]{{make}} </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">]*ngFor="let model of vehicle.models">{{model}}

 

    [ERROR ->]{{model}} "): VehicleDirective@36:15 Can't bind to 'ngForOf' since it isn't a known property of 'option'. ("refixbox">SELECT]*ngFor="let year of vehicle.years">{{year}} "): 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">SELECT [ERROR ->]{{year}} "): VehicleDirective@47:24 Can't bind to 'ngForOf' since it isn't a known property of 'option'. ("ateSelect" [(ngModel)]="vehicleData.stateSelect" class="prefixbox">]*ngFor="let state of vehicle.regStates">{{state}} "): 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 ->]{{state}} "): VehicleDirective@55:24 Can't bind to 'ngForOf' since it isn't a known property of 'option'. ("lorSelect" [(ngModel)]="vehicleData.colorSelect" class="prefixbox">]*ngFor="let color of vehicle.colors">{{color}} "): 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 ->]{{color}} "): VehicleDirective@68:24

问题出在哪里?我已经验证了很多解决方案,但没有找到解决方法。同样的代码在本地可以正常工作。

admin 更改状态以发布 2023年5月22日
0
0 Comments

在添加浏览器模块之后,它运行正常。\n

 import { BrowserModule } from '@angular/platform-browser';
 @NgModule({
     imports: [BrowserModule ]
  })

0
0 Comments

我遇到了完全相同的错误,我已经包含了CommonModule和BrowserModule,但是我仍然在浏览器上看到了相同的错误信息。

最后,我找到了我的问题原因,那就是我忘记将我的组件添加到app.module.ts中了,以防有其他人遇到相同的行为。

0