Skip to content

Can we bind [(ngModel)] to JsonEditor ? #12

Open
@SwapnilChidrawar

Description

@SwapnilChidrawar

In this editor in order to get the changed data in editor we are using onChange method detection. Instead, Can we use angular's [(ngModel)] (Two way binding ) so that we will not need to hit onChange method.

Following is my code with the OnChange method in component.ts file:
`
public editorOptions: JsonEditorOptions;
@ViewChild(JsonEditorComponent) editor: JsonEditorComponent;

constructor() {
 this.editorOptions = new JsonEditorOptions();
}

ngOnInit() {
 this.editorOptions.onChange = () => {
  this.change();
};

change(): void {
   console.log(this.editor.getText());  
}

Inside the template we are using as follows :
"<div class="jsoneditor-wrapper" [ngClass]="cssClass">
<json-editor
[options]="editorOptions"
[data]="data">
"

The issue is getting occurred very first time without making any change to editor, we are going to fetch the data which already has JSON object, but because change event is not detected by the jsoneditor it is giving me undefined value while doing editor.getText() method. For this reason it will be great if we use Angular's Two way binding approach.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions