I am facing a problem. I want to get an htmlelement in my view in angular2 this is my view
<p>
<button (click)="setJSON()">Set JSON</button>
<button (click)="getJSON()">Get JSON</button>
</p>
<div id="jsoneditor">
</div>
I would like to access the jsoneditor in my class and pass it to my JSONEditor https://github.com/josdejong/jsoneditor/blob/master/docs/api.md to tell it where to rendering the editor.
This is my class:
export class JsonComponent {
container: HTMLElement;
editor1: JSONEditor;
options;
constructor(public router: Router, public element: ElementRef) {
this.container = this.element.nativeElement
this.options = { "mode": "tree", "search": true };
this.editor1 = new JSONEditor(this.container,this. options);
var json = {
"Array": [1, 2, 3],
"Boolean": true,
"Null": null,
"Number": 123,
"Object": { "a": "b", "c": "d" },
"String": "Hello World"
};
this. editor1.set(json);
this. editor1.expandAll();
}
setJSON() {
alert("setJson");
}
getJSON() {
alert("getJson");
}
}