Angular 角度:Can';t绑定到';ngClass';因为它不是';t'的已知属性;李';

Angular 角度:Can';t绑定到';ngClass';因为它不是';t'的已知属性;李';,angular,Angular,您好,我在视觉代码和角度10中遇到此错误: 无法绑定到'ngClass',因为它不是'li'的已知属性。 我将把我所有的代码附加到这个组件中,我不知道如何解决它 我的html模板是: 我的组件ts是: import { Component, OnInit } from '@angular/core'; import { Router } from '@angular/router'; import { CommunicationService } from '../../shar

您好,我在视觉代码和角度10中遇到此错误:

无法绑定到'ngClass',因为它不是'li'的已知属性。

我将把我所有的代码附加到这个组件中,我不知道如何解决它

我的html模板是:

我的组件ts是:

import {
  Component,
  OnInit
} from '@angular/core';
import { Router } from '@angular/router';

import {
  CommunicationService
} from '../../share/communication/communication.service';

@Component({
  selector: 'app-menumovil',
  templateUrl: './menu-movil.component.html',
  styleUrls: ['./menu-movil.component.scss']
})
export class MenuMovilComponent implements OnInit {
  public esNosaltres = false;
  public esInicio = true;
  public esCarne = false;
  public esVerdura = false;
  public esFruta = false;
  public esProducto = false;

  constructor(
    private router: Router,
    private communication: CommunicationService,
  ) { }

  ngOnInit(): void {
  }

  public allMenuoff = () => {
    this.esNosaltres = false;
    this.esInicio = false;
    this.esCarne = false;
    this.esFruta = false;
    this.esVerdura = false;
    this.esProducto = false;
  }

  public eventOnClickMenu = (tipo: string) => {
    this.communication.setMenuType(tipo);

    this.allMenuoff();

    switch (tipo) {
      case 'inicio':
        this.esInicio = true;
        this.router.navigateByUrl('/');
        break;
      case 'nosaltres':
        this.esNosaltres = true;
        this.router.navigateByUrl('/nosotros');
        break;
      case 'producto':
        this.router.navigateByUrl('/');
        this.esProducto = true;
        break;
      case 'fruta':
        this.router.navigateByUrl('/');
        this.esFruta = true;
        break;
      case 'verdura':
        this.router.navigateByUrl('/');
        this.esVerdura = true;
        break;
      case 'carne':
        this.router.navigateByUrl('/');
        this.esCarne = true;
        break;
    }

  }
}
该模块是:

import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import {
  FormsModule,
  ReactiveFormsModule
} from '@angular/forms';

import { MenuMovilComponent } from './menu-movil.component';

@NgModule({
  declarations: [MenuMovilComponent],
  exports: [MenuMovilComponent],
  imports: [
    CommonModule,
    FormsModule,
    ReactiveFormsModule,

    NgModule
    ]
})
export class MenuMovilModule { }
在styles.scss中,我有:

.activoOn {
  background-color: black !important;

}

.activoOn a {
  color: silver !important;
}

.activoOff {
  background-color: unset !important;
}
如果你需要更多信息,请告诉我

为什么我会犯这个错误

Thx

======================================================================== 更新1:

@NgModule({
  declarations: [MenuComponent],
  exports: [ MenuComponent ],
  imports: [
    CommonModule,
    FormsModule,
    ReactiveFormsModule,
    BrowserModule, // <<------ not working with it...
    NgModule
  ]
})

我正在app.module中导入它。

在您的NgModule中导入
BrowserModule

import { BrowserModule } from "@angular/platform-browser";

@NgModule({
  imports: [BrowserModule, ...]
...
})

如果您已经拥有CommonModule/BrowserModule/FormsModule/NgModule,但它仍然不工作,请确保重新启动并构建应用程序。如果它仍然不工作,则可以重新检查声明[],并在app.module.ts文件中导入[]数组。

BrowserModule应仅在根模块中导入。我觉得你的代码很正确。我猜您会出现这个错误,可能是因为您没有将模块导入应用程序使用的另一个模块,或者您的IDE需要重新启动。如果问题仍然存在,请创建stackblitz,我很乐意看一看。我同意@ionut-t,restart有时可以解决这些奇怪的问题。我正在重新启动它,但还没有找到解决方案。我觉得代码还可以。我用新信息更新了这个问题
import { BrowserModule } from "@angular/platform-browser";

@NgModule({
  imports: [BrowserModule, ...]
...
})