gpt4 book ai didi

javascript - ionic 3、自定义组件和ngClass绑定(bind)问题

转载 作者:行者123 更新时间:2023-12-03 02:04:09 29 4
gpt4 key购买 nike

我尝试在 Ionic3 中制作一个简单的组件来显示点来指示我们所在的页面。我使用 ionicgenerate 命令来生成此组件:

import { Component, Input } from '@angular/core';

@Component({
selector: 'panel-indicator',
templateUrl: 'panel-indicator.html'
})
export class PanelIndicatorComponent {

@Input() page: number;

constructor() {
console.log('Hello PanelIndicatorComponent Component');
this.page = 1;
}

}

这是模板部分:

<div class="indicator-list">
<div class="indicator selected" [ngClass]="{'selected': page === 1}"></div>
<div class="indicator" [ngClass]="{'selected': page === 2}"></div>
<div class="indicator" [ngClass]="{'selected': page === 3}"></div>
</div>

当我删除 ngclass 属性时,没有问题。但是,当我添加它时,出现以下错误:

Can't bind to 'ngClass' since it isn't a known property of 'div'. ("
<div class="indicator-list">

<div class="indicator selected" [ERROR ->][ngClass]="{'selected': page === 1}"></div>

<div class="indicator" [ngClass]="{'selected': page =="): ng:///ComponentsModule/PanelIndicatorComponent.html@4:34
Can't bind to 'ngClass' since it isn't a known property of 'div'. ("iv class="indicator selected" [ngClass]="{'selected': page === 1}"></div>

<div class="indicator" [ERROR ->][ngClass]="{'selected': page === 2}"></div>

<div class="indicator" [ngClass]="{'selected': page =="): ng:///ComponentsModule/PanelIndicatorComponent.html@6:25
Can't bind to 'ngClass' since it isn't a known property of 'div'. ("
<div class="indicator" [ngClass]="{'selected': page === 2}"></div>

<div class="indicator" [ERROR ->][ngClass]="{'selected': page === 3}"></div>

</div>
"): ng:///ComponentsModule/PanelIndicatorComponent.html@8:25
at syntaxError (http://localhost:8100/build/vendor.js:101030:34)
at TemplateParser.parse (http://localhost:8100/build/vendor.js:124893:19)
at JitCompiler._parseTemplate (http://localhost:8100/build/vendor.js:134321:37)
at JitCompiler._compileTemplate (http://localhost:8100/build/vendor.js:134296:23)
at http://localhost:8100/build/vendor.js:134198:62
at Set.forEach (<anonymous>)
at JitCompiler._compileComponents (http://localhost:8100/build/vendor.js:134198:19)
at http://localhost:8100/build/vendor.js:134068:19
at Object.then (http://localhost:8100/build/vendor.js:101019:77)
at JitCompiler._compileModuleAndComponents (http://localhost:8100/build/vendor.js:134067:26)

我没有找到任何关于这个问题的信息。因此,如果您有想法,欢迎您。

感谢您的阅读。

最佳答案

您需要添加BrowserModule

@NgModule(
imports: [BrowserModule, /* other imports */] from '@angular/platform-browser',
...
)

如果它在子模块中,则导入 CommonModule。

import { CommonModule } from "@angular/common"

关于javascript - ionic 3、自定义组件和ngClass绑定(bind)问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49881867/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com