将 JSON 对象转换为漂亮打印的 JSON 的 Angular 2 管道 [英] Angular 2 pipe that transforms JSON object to pretty-printed JSON
问题描述
尝试编写一个 Angular 2 管道,该管道将接受一个 JSON 对象字符串并将其返回打印/格式化以显示给用户.
例如,它会这样:
{身份证":1,"number": "K3483483344","状态": "CA",活动":真实}
并在 HTML 中显示时返回如下所示的内容:
所以在我看来,我可以有类似的东西:
{{ record.jsonData |漂亮的打印}} </td> 解决方案 我想添加一种更简单的方法来做到这一点,使用内置的 json
管道:
{{data |json}}</pre>
这样,格式就被保留了.
Trying to write an Angular 2 pipe that will take a JSON object string and return it pretty-printed/formatted to display to the user.
For example, it would take this:
{
"id": 1,
"number": "K3483483344",
"state": "CA",
"active": true
}
And return something that looks like this when displayed in HTML:
So in my view I could have something like:
<td> {{ record.jsonData | prettyprint }} </td>
解决方案 I would like to add an even simpler way to do this, using the built-in json
pipe:
<pre>{{data | json}}</pre>
This way, the formatting is preserved.
这篇关于将 JSON 对象转换为漂亮打印的 JSON 的 Angular 2 管道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文
登录
关闭
扫码关注1秒登录
发送“验证码”获取
|
15天全站免登陆