Angular 2: pipes - How to format a phone number?

前端 未结 5 1664
灰色年华
灰色年华 2020-12-14 17:18

I\'ve searched here and there, and I am not able to find something specific about formatting a phone number.

Currently, I am retrieving phone numbers form a JSON in

5条回答
  •  不知归路
    2020-12-14 17:29

    When formatting phone numbers from a JSON data service, this was the simplest solution I could think of.

    0{{contact.phone.home | slice:0:1}}-{{contact.phone.home | slice:1:3}}-{{contact.phone.home | slice:3:5}}-{{contact.phone.home | slice:5:8}}

    This will format "25565115" into "02-55-65-115"

    Hope this helps someone!

提交回复
热议问题