是否有用于json的json格式程序(指令/组件)? [英] Is there a json-formatter (directive/component) for angular?
本文介绍了是否有用于json的json格式程序(指令/组件)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在将应用程序从AngularJS升级到Angular.在AngularJS中,我使用了 https://github.com/mohsen1/json-formatter 来显示美化的json.有没有替代的角度?
I'm upgrading an app from AngularJS to Angular. In AngularJS I used https://github.com/mohsen1/json-formatter to get displayed a beautified json. Is there an alternative for angular?
推荐答案
您可以使用 json- formatter-js 包
import JSONFormatter from 'json-formatter-js';
@Directive({
selector: 'json-formatter'
})
export class JsonFormatterDirective implements OnChanges {
@Input() json: any;
constructor(private elRef: ElementRef) { }
ngOnChanges() {
if (this.json) {
const formatter = new JSONFormatter(this.json);
this.elRef.nativeElement.appendChild(formatter.render());
}
}
}
Plunker Example
或为angular2创建相同的组件
or create the same component for angular2
Plunker Example
这篇关于是否有用于json的json格式程序(指令/组件)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文