简体   繁体   English

无法绑定到“ngif”,因为它不是“span”的已知属性

[英]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上的大多数答案都说在父模块中包含CommonModuleBrowserModule ,虽然这适用于我升级的其他组件,但奇怪的是它不适用于这个

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.

相关问题 angular 2 控制台错误无法绑定到“ngIf”,因为它不是“span”的已知属性 - angular 2 console error Can't bind to 'ngIf' since it isn't a known property of 'span' Angular 6 无法绑定到“*ngIf”,因为它不是已知属性 - Angular 6 Can't bind to '*ngIf' since it isn't a known property Angular 2无法绑定到'ngif',因为它不是已知属性 - Angular 2 Can't bind to 'ngif' since it isn't a known property 无法绑定到“ngIf”,因为它不是“form”的已知属性 - Can't bind to 'ngIf' since it isn't a known property of 'form' 无法绑定到“ngIf”,因为它不是“表”的已知属性 - Can't bind to 'ngIf' since it isn't a known property of 'table' 无法绑定到“owlDateTimeTrigger”,因为它不是“span”的已知属性 - Can't bind to 'owlDateTimeTrigger' since it isn't a known property of 'span' 无法绑定到“ ngIF”,因为它不是“ ion-item”的已知属性 - Can't bind to 'ngIF' since it isn't a known property of 'ion-item' 错误:无法绑定到“ngIf”,因为它不是“form”的已知属性 - Error: Can't bind to 'ngIf' since it isn't a known property of 'form' Angular 抛出错误:无法绑定到“ngIf”,因为它不是“ng-container”的已知属性 - Angular throws error: can't bind to “ngIf” since it isn't a known property of “ng-container” 发生相同的问题:无法绑定到“ngIf”,因为它不是“div”的已知属性 - Same Issue occured : Can't bind to 'ngIf' since it isn't a known property of 'div'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM