我正在将应用程序从 AngularJS 升级到 Angular。在 AngularJS 中我使用了https://github.com/mohsen1/json-formatter https://github.com/mohsen1/json-formatter显示美化的 json。有角度的替代品吗?
您可以使用json 格式化程序-js https://github.com/mohsen1/json-formatter-js package
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());
}
}
}
笨蛋的例子 https://plnkr.co/edit/KYsEAj1og45Z0mJ8FUK8?p=preview
或为 angular2 创建相同的组件
笨蛋的例子 https://plnkr.co/edit/6Cbs6pIPqGlXM0hmXF9n?p=preview
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)