Is there jso formatting (directive / component) for angular?
I am upgrading my app from AngularJS to Angular. In AngularJS, I used https://github.com/mohsen1/json-formatter to render the decorated json. Is there an alternative for angular?
+3
source to share
1 answer
You can 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()); } } }
or create the same component for angular2
+4
source to share