You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Angular 14.2.10版本下使用ngx-mask组件遇到问题求助

ngx-mask在Angular 14.2.10中配置后报错的解决办法

问题描述

使用Angular 14.2.10版本,在app.module.ts中按如下配置ngx-mask:

import { NgxMaskModule } from 'ngx-mask';
@NgModule({
  imports: [
    NgxMaskModule.forRoot()
  ]
})

配置后仍出现报错,错误截图:
ngx-mask错误截图

解决步骤

  • 检查版本兼容性
    Angular 14需要匹配对应版本的ngx-mask,执行npm list ngx-mask查看当前版本,若不是14.x.x系列,执行以下命令重装适配版本:

    npm uninstall ngx-mask
    npm install ngx-mask@14 --save
    
  • 确认模块导入完整性
    确保app.module.ts的模块配置完整,示例如下:

    import { NgxMaskModule } from 'ngx-mask';
    
    @NgModule({
      declarations: [
        // 你的项目组件
      ],
      imports: [
        // 其他依赖模块
        NgxMaskModule.forRoot()
      ],
      providers: [],
      bootstrap: [AppComponent]
    })
    export class AppModule { }
    
  • 清理缓存重启项目
    执行以下命令清理缓存并重新安装依赖后重启开发服务:

    npm cache clean --force
    rm -rf node_modules package-lock.json
    npm install
    ng serve
    

内容的提问来源于stack exchange,提问作者Miriam

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.03 13:45:27