I share how to resolve this detail using a mask
1.- In your view you must place your text box with an identifier as shown
<input type="text" id="phone" placeholder="(55)-5555-5555">
2.- In your component, add AfterViewInit so that when the main view finishes loading, start loading the secondary view which will have the script to perform the function of the telephone format as shown below.
import { Component, AfterViewInit } from '@angular/core';
@Component({
selector:'my-app',
template: '<input type="text" id="phone" placeholder="(55)-5555-5555"})
export class AppComponent implements AfterViewInit
{
ngAfterViewInit()
{
document.getElementById('phone').addEventListener('input', function (e)
{
var x = e.target.value.replace(/\D/g, '').match(/(\d{0,2})(\d{0,4})(\d{0,4})/);
e.target.value = !x[2] ? x[1] : '(' + x[1] + ') ' + x[2] + (x[3] ? '-' + x[3] : '');
});
}
}
Ok, explain code:
NgAfterView load of the script. With document.getElementById('phone') select the id phone
AddEventListener allow the moment convert in real time to phone format
If you required change 555-5555-55, you may change the section .match(/\d{0,2}) to the numbers to want
Regards