I have the following directive groupingFormat which perform grouping to an input text
when user use the key up:
@Directive({
selector: '[groupingFormat]'
})
export class GroupingFormatDirective {
private el: HTMLInputElement;
constructor(elRef: ElementRef) {
this.el = elRef.nativeElement;
}
ngAfterViewInit(): void {
let elem : HTMLInputElement = this.el;
elem.addEventListener('keyup',() => {
this.el.value = this.digitGrouping(this.el.value);
});
}
}
Example of usage:
<input type="text" #myValue="ngModel" name="my_value" [(ngModel)]="myObj.myValue" id="my_value" required groupingFormat>
This directive is working as expected but now I have new requirement: The input text should use the directive also when the page is load and also if the a form is open inside the page with the input becoming visible.
Is there an easy way to update the directive to support this functionality or any alternative solution? Attach another directive ? Thanks.