[英]Can't bind to 'ngif' since it isn't a known property of 'span'
I have created a Hybrid app using ngUpgrade and am currently going through my directives upgrading them to Angular components.我已经使用 ngUpgrade 创建了一个混合应用程序,目前正在通过我的指令将它们升级到 Angular 组件。
I have ran into this issue and cannot seem to fix it我遇到了这个问题,似乎无法解决
Can't bind to 'ngif' since it isn't a known property of 'span'无法绑定到“ngif”,因为它不是“span”的已知属性
Most answers on SO say to include CommonModule
or BrowserModule
within the parent Module, and whilst this worked for other components I have upgraded, it curiously hasnt worked for this one SO上的大多数答案都说在父模块中包含CommonModule
或BrowserModule
,虽然这适用于我升级的其他组件,但奇怪的是它不适用于这个
Note if I remove *ngIf
the component renders correctly, it only fails when I try to use *ngIf
请注意,如果我删除*ngIf
组件正确呈现,它只会在我尝试使用*ngIf
时失败
Here is my module definition这是我的模块定义
import { CommonModule } from "@angular/common";
import { NgModule } from "@angular/core";
import { DashboardBoxSmallComponent } from "./dashboard/dashboardBoxSmall.component";
import { MiscDirectivesModule } from "./_misc/_misc.directives.module";
import { VehicleDirectivesModule } from "./_vehicle/_vehicle.directives.module";
@NgModule({
imports: [
CommonModule,
MiscDirectivesModule,
VehicleDirectivesModule
],
entryComponents: [
DashboardBoxSmallComponent
],
declarations: [
DashboardBoxSmallComponent
]
})
export class DirectivesModule {
constructor() {
}
}
The component.ts itself component.ts 本身
import { Component, Input } from "@angular/core";
import "./dashboardBoxSmall.component.scss";
@Component({
selector: "dashboard-box-small",
template: require("./dashboardBoxSmall.component.html")
})
export class DashboardBoxSmallComponent {
@Input() boxIcon: string;
@Input() boxIconClass: string;
@Input() boxTitle: string;
@Input() boxSubtitle: string;
// ---
constructor() {
}
}
The HTML HTML
<div class="ml-10 layout-column overflow-hidden">
<div class="bold font-size-14">
<ng-content></ng-content>
<span *ngIf="boxTitle">{{boxTitle}}</span>
</div>
<div class="text-muted font-size-11">{{boxSubtitle}}</div>
</div>
Turns out that the clue was in the error message... it said "ngif" not "ngIf".原来线索在错误消息中......它说“ngif”而不是“ngIf”。
Initially I thought that was just how Angular error messages work, but then it dawned on me that my webpack configuration may be inadvertently transforming HTML to lowercase (why?).最初我以为这就是 Angular 错误消息的工作原理,但后来我意识到我的 webpack 配置可能无意中将 HTML 转换为小写(为什么?)
Turns out this was correct, I had to add an option to html-loader
to prevent it transforming to lowercase.事实证明这是正确的,我不得不向html-loader
添加一个选项以防止它转换为小写。
{
test: /\.html$/,
loader: 'html-loader',
options: { minimize: true, caseSensitive: true }
},
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.