如何使用 AngularJS 过滤器将数字格式化为前导零? [英] How can I use an AngularJS filter to format a number to have leading zeros?

查看:27
本文介绍了如何使用 AngularJS 过滤器将数字格式化为前导零?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我查看了文档.我想要的是我的数字有四位数字和前导零.

I checked the documentation. What I would like is for my numbers to have four digits and leading zeros.

22 to 0022
1  to 0001

有人可以帮忙告诉我这个数字或其他类型的过滤器是否可行吗?

Can someone help and tell me if this is possible with the number or another kind of filter?

推荐答案

无需过滤器,只需在 html 中使用表达式

No filter required, Just use an expression in your html

{{("00000"+1).slice(-6)}}      // '000001'

{{("00000"+123456).slice(-6)}} // '123456'

这篇关于如何使用 AngularJS 过滤器将数字格式化为前导零?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆