Skip to content
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

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

Open
SwapnilChidrawar opened this issue Jul 4, 2018 · 4 comments
Open

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

SwapnilChidrawar opened this issue Jul 4, 2018 · 4 comments
Labels
enhancement New feature or request

Comments

@SwapnilChidrawar
Copy link

SwapnilChidrawar commented Jul 4, 2018

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.

@mariohmol
Copy link
Owner

You need to bind the change method.. remember? https://github.com/mariohmol/ang-jsoneditor/blob/master/src/app/demo/demo.component.ts#L49

@osmanraifgunes
Copy link
Contributor

osmanraifgunes commented Jan 21, 2020

Cannot use event.target.get() or event.currentTarget.get()

this seems necessary if the ui has multiple (not certain count) editors.

@ropstah
Copy link

ropstah commented Apr 4, 2020

@mariohmol first: thank you for this library!

I got to this thread trying to see if I could use two-way databinding. I've been using this component for quite a few years already, both in jQuery, AngularJS and your Angular version and I always remembered that two-way databinding was 'a thing'...

You need to bind the change method.. remember? https://github.com/mariohmol/ang-jsoneditor/blob/master/src/app/demo/demo.component.ts#L49

I don't really remember... Can you explain why it is not possible to use two-way binding?

@mariohmol mariohmol reopened this May 3, 2020
@mariohmol
Copy link
Owner

Hi!!
I tried to make this to work but when using the ngModel with ngpackagr I faced a bug there =(

ng-packagr/ng-packagr#1151

If u can ask in there if is any news!!

Thanks!

@mariohmol mariohmol added the enhancement New feature or request label May 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants