Angular 6不调用ngClass
创始人
2024-10-16 06:30:23
0

在Angular 6中,可以使用以下方法来解决不调用ngClass的问题:

  1. 确保在组件中导入了FormsModuleReactiveFormsModule,并将其添加到@NgModule装饰器的imports数组中。
import { FormsModule } from '@angular/forms';

@NgModule({
  imports: [
    FormsModule
  ],
  // other configurations
})
export class AppModule { }
  1. 确保在组件模板中正确使用ngClass指令,并且表达式返回布尔值。
Example

其中,condition1condition2是在组件中定义的布尔类型变量。

  1. 如果在组件代码中修改了ngClass表达式的条件,确保在更改后调用了ChangeDetectorRefdetectChanges()方法。
import { Component, ChangeDetectorRef } from '@angular/core';

@Component({
  selector: 'app-example',
  template: `
    
Example
` }) export class ExampleComponent { condition1: boolean = true; condition2: boolean = false; constructor(private cdr: ChangeDetectorRef) { } changeConditions() { this.condition1 = !this.condition1; this.condition2 = !this.condition2; this.cdr.detectChanges(); } }

在上述示例中,当点击按钮时,会切换condition1condition2的值,并调用detectChanges()方法来更新视图。

如果以上方法都没有解决问题,可以尝试重启Angular开发服务器或清除浏览器缓存,有时候这些问题可能是由于开发环境或缓存问题引起的。

相关内容

热门资讯

poker辅助器免费安装!aa... poker辅助器免费安装!aapoker插件下载(透视)教程-切实了解真的有挂1、poker辅助器免...
透视解迷!wepoker辅助器... 透视解迷!wepoker辅助器官方(透视)哈糖大菠萝挂,教程绝活(的确有挂)-哔哩哔哩1、让任何用户...
hhpoker为什么一直输!h... hhpoker为什么一直输!hhpoker透视实战视频(透视)神器-都是科普真的有挂1、让任何用户在...
透视揭露!wepoker破解器... 透视揭露!wepoker破解器有用吗(透视)cloudpoker透视,教程大纲(有挂神器)-哔哩哔哩...
约局吧如何查看是否有挂!竞技联... 约局吧如何查看是否有挂!竞技联盟辅助(透视)app-总是必备有挂1)约局吧如何查看是否有挂有没有挂:...
透视总结!wepoker辅助透... 透视总结!wepoker辅助透视(透视)poker world辅助器,教程方针(今日头条)-哔哩哔哩...
aapoker如何设置胜率!h... aapoker如何设置胜率!hhpoker怎么开透视(透视)工具-一贯详情是有挂1、玩家可以在aap...
透视关于!德州透视hhpoke... 透视关于!德州透视hhpoker(透视)pokemomo辅助软件,教程窍门(了解有挂)-哔哩哔哩po...
hhpoker免费透视脚本!h... hhpoker免费透视脚本!hhpoker有透视的吗(透视)软件-原来辅助真的有挂在进入hhpoke...
透视解谜!pokeplus脚本... 透视解谜!pokeplus脚本(透视)聚星ai辅助工具收费多少,教程策略(有挂秘籍)-哔哩哔哩聚星a...