-
Notifications
You must be signed in to change notification settings - Fork 85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Are you planning to create an Angular 2 component with similar functionality? #62
Comments
For Angular 2 create a simple component in your codebase that uses JSON Formatter JS. |
Could somebody post an example of such a component here? |
@mhalttu loosely something like: import { Component, OnChanges, Input, ElementRef, ViewChild, Renderer } from '@angular/core';
import { isObject } from 'rxjs/util/isObject';
import { isArray } from 'rxjs/util/isArray';
import JSONFormatter from 'json-formatter-js';
@Component({
selector: 'json-viewer',
template: `<div #jsonViewer></div>`,
styleUrls: ['./json-viewer.component.sass']
})
export class JsonViewerComponent implements OnChanges {
@ViewChild(`jsonViewer`) input: ElementRef;
@Input() json: Array<any> | Object | any;
constructor() { }
ngOnChanges() {
// Do nothing without data
if (!isObject(this.json) && !isArray(this.json)) {
return;
}
const formatter = new JSONFormatter(this.json);
this.input.nativeElement.appendChild(formatter.render());
}
} |
Here is an example for angular2 https://plnkr.co/edit/6Cbs6pIPqGlXM0hmXF9n?p=preview. If Mohsen Azimi doesn't mind i can make it as library |
@alexzuza Very AWESOME! Thank you. While I was able to get it to work in Angular 2 using basic Maybe you can release this as an NPM package for easy consumption. Very good work to @mohsen1 for creating the original code as well!!! It was hard to find a library that could take plain JSON and convert it into a tree view with expand/collapse - they all wanted custom Thanks guys. |
@jwhitmarsh Great minimal example - except I had to use |
No description provided.
The text was updated successfully, but these errors were encountered: