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; }

相关内容

热门资讯

截至发稿!哈糖大菠萝能开挂吗,... 截至发稿!哈糖大菠萝能开挂吗,智星菠萝透视,好像存在有挂(有挂方针)1、智星菠萝透视免费脚本咨询教程...
最新技巧!wepoker是不是... 最新技巧!wepoker是不是有人用挂,wepoker底牌透视,果然真的有挂(有人有挂)运辅助工具,...
备受关注的!impoker辅助... 备受关注的!impoker辅助,德普之星怎么开辅助,总是真的有挂(有挂技巧)1、实时德普之星怎么开辅...
重大发现!wepoker好友助... 您好,这款游戏可以开挂的,确实是有挂的,需要了解加去威信【136704302】很多玩家在这款游戏中打...
此事迅速冲上热搜!wepoke... 此事迅速冲上热搜!wepoker透视脚本免费app,德普之星透视辅助软件是真的吗,切实真的有挂(有挂...
大神推荐!wepoker网页版... 大神推荐!wepoker网页版透视方法,wepoker-h5下载,竟然是有挂(有挂猫腻)辅助器是一种...
针对!wepoker私人局外卦... 针对!wepoker私人局外卦,德普之星透视辅助软件是真的吗,本来真的是有挂(果真有挂)1、每一步都...
总算清楚!wepoker免费透... 总算清楚!wepoker免费透视脚本,约局吧透视挂下载,都是是有挂(有挂实锤)1、任何wepoker...
于此同时!wpk真吗,德普辅助... 于此同时!wpk真吗,德普辅助器怎么用,其实是真的有挂(有挂透视)1、下载好德普辅助器怎么用透视辅助...
让我来分享经验!pokemmo... 让我来分享经验!pokemmo辅助器脚本下载,大菠萝免费辅助,一直真的是有挂(有挂教学)1、大菠萝免...