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?
You can either use 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());
}
}
}
Plunker Example
or create the same component for angular2
Plunker Example
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With