Angularmaterial的datepicker与text-mask库不能很好地配合使用
创始人
2024-10-28 08:33:14
0
  1. 首先,引入text-mask库:

import createTextMaskInputElement from 'text-mask-core/src/createTextMaskInputElement'; import {Directive, ElementRef, HostListener} from '@angular/core';

@Directive({ selector: '[textMask][ngModel]' }) export class TextMaskDirective { private textMaskInputElement: any;

constructor(public elementRef: ElementRef) {}
...

}

  1. 然后,在组件中使用:

Enter a date

  1. 最后,在组件类中添加以下代码:

const rawMask = [/\d/, /\d/, '-', /\d/, /\d/, '-', /\d/, /\d/];

public dateMask = { guide: false, showMask: true, mask: rawMask };

constructor(private elementRef: ElementRef) {}

ngAfterViewInit() { setTimeout(() => { this.textMaskInputElement = createTextMaskInputElement( {inputElement: this.elementRef.nativeElement}, this.dateMask ); this.textMaskInputElement.update(this.dateValue); }, 0); // Timeout is required for avoid error: Expression has changed after it was checked }

@HostListener('input', ['$event']) onInput(event) { this.dateValue = event.target.value; }

相关内容

热门资讯

科普攻略!wepoker透视是... 科普攻略!wepoker透视是真的吗(辅助挂)一贯真的是有挂(果真有挂辅助软件)1、点击下载安装,脚...
揭秘攻略!wepoker代打辅... 揭秘攻略!wepoker代打辅助(辅助挂)总是是有挂(讲解有挂辅助软件)1、免费脚本咨询教程、免费脚...
玩家必看攻略!wepoker免... 玩家必看攻略!wepoker免费脚本弱密码(辅助挂)一直真的是有挂(有挂方法辅助脚本)1、任何透视是...
大家学习交流!hhpoker哪... 大家学习交流!hhpoker哪个俱乐部靠谱(辅助挂)都是是有挂(有挂教程辅助插件)1、许多玩家不知道...
每日必看推荐!来玩app 德州... 每日必看推荐!来玩app 德州 辅助(辅助挂)切实是有挂(存在有挂辅助插件)1、模拟器是什么优化,俱...
查到实测辅助!pokemmo手... 查到实测辅助!pokemmo手机脚本(辅助挂)确实真的是有挂(有挂秘籍辅助方法)1、用户打开应用后不...
技术分享!hhpoker破解工... 技术分享!hhpoker破解工具(辅助挂)好像是真的有挂(证实有挂辅助方法)是不是有人用挂微扑克wp...
重要通知!wepokerplu... 重要通知!wepokerplus外挂(辅助挂)好像是真的有挂(果真有挂辅助工具)脚本下载中分为三种模...
技术分享!wepoker有辅助... 技术分享!wepoker有辅助吗(辅助挂)总是存在有挂(有挂技巧辅助方法)1、首先打开辅助器下载最新...
一秒答解!agpoker辅助(... 一秒答解!agpoker辅助(辅助挂)确实真的有挂(的确有挂辅助攻略)1、进入游戏-大厅左侧-新手福...