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

Support Angular 18 #147

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 17 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ Angular Json Editor (wrapper for [jsoneditor](https://github.com/josdejong/jsone

[StackBlitz template](https://stackblitz.com/edit/ang-jsoneditor)

Working with latest Angular 16.
Working with latest Angular 18.

![Demo Image](/src/assets/printDemo.png)

## Installation

To install this library with npm, run below command:

```sh
$ npm install --save jsoneditor ang-jsoneditor

```

Example:

Expand All @@ -27,25 +28,7 @@ Example:

### Configuration

First, Import Angular JsonEditor module in root

```ts
import { NgJsonEditorModule } from 'ang-jsoneditor'

@NgModule({
declarations: [
AppComponent
],
imports: [
....,
NgJsonEditorModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
```
Then setup your component models as below :
Import the standalone component as below:

```ts
import { Component, ViewChild } from '@angular/core';
Expand All @@ -54,19 +37,21 @@ import { JsonEditorComponent, JsonEditorOptions } from 'ang-jsoneditor';
@Component({
selector: 'app-root',
template: '<json-editor [options]="editorOptions" [data]="data"></json-editor>',
styleUrls: ['./app.component.css']
styleUrls: ['./app.component.css'],
imports: [JsonEditorComponent]
})
export class AppComponent {
public editorOptions: JsonEditorOptions;
public data: any;
// optional
@ViewChild(JsonEditorComponent, { static: false }) editor: JsonEditorComponent;

constructor() {
constructor() {
this.editorOptions = new JsonEditorOptions()
this.editorOptions.modes = ['code', 'text', 'tree', 'view']; // set all allowed modes
//this.options.mode = 'code'; //set only one mode
this.data = {"products":[{"name":"car","product":[{"name":"honda","model":[{"id":"civic","name":"civic"},{"id":"accord","name":"accord"},{"id":"crv","name":"crv"},{"id":"pilot","name":"pilot"},{"id":"odyssey","name":"odyssey"}]}]}]}

this.data = {"products":[{"name":"car","product":[{"name":"honda","model":[{"id":"civic","name":"civic"},{"id":"accord","name":"accord"},{"id":"crv","name":"crv"},{"id":"pilot","name":"pilot"},{"id":"odyssey","name":"odyssey"}]}]}]}
}

}
Expand All @@ -82,7 +67,7 @@ Note : For better styling, add below line to your main style.css file

Build it integrated with ReactiveForms:

```ts
```ts
this.form = this.fb.group({
myinput: [this.data]
});
Expand All @@ -96,11 +81,11 @@ this.form = this.fb.group({

### Extra Features

Besides all the
[configuration options](https://github.com/josdejong/jsoneditor/blob/master/docs/api.md)
Besides all the
[configuration options](https://github.com/josdejong/jsoneditor/blob/master/docs/api.md)
from the original jsoneditor, Angular Json Editor supports one additional option:

_expandAll_ - to automatically expand all nodes upon json loaded with the _data_ input.
_expandAll_ - to automatically expand all nodes upon json loaded with the _data_ input.

# Troubleshoot

Expand Down Expand Up @@ -153,7 +138,7 @@ let editorOptions: JsonEditorOptions = new JsonEditorOptions(); (<any>this.edito

See the [issue](https://github.com/mariohmol/ang-jsoneditor/issues/57)

## Internet Explorer
## Internet Explorer

If you want to support IE, please follow this guide:
* https://github.com/mariohmol/ang-jsoneditor/issues/44#issuecomment-508650610
Expand All @@ -162,7 +147,7 @@ If you want to support IE, please follow this guide:

To use multiple jsoneditors in your view you cannot use the same editor options.

You should have something like:
You should have something like:

```html
<div *ngFor="let prd of data.products" class="w-100-p p-24" >
Expand All @@ -187,7 +172,7 @@ When publishing it to npm, look over this docs: https://docs.npmjs.com/misc/deve

# Collaborate

Fork, clone this repo and install dependencies.
Fork, clone this repo and install dependencies.
This project just works with webpack 4 (dont change to 5):

```sh
Expand Down
4 changes: 2 additions & 2 deletions projects/ang-jsoneditor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
"angular"
],
"peerDependencies": {
"@angular/common": "^17.0.0",
"@angular/core": "^17.0.0",
"@angular/common": "^17.0.0 || ^18.0.0",
"@angular/core": "^17.0.0 || ^18.0.0",
"jsoneditor": "^9.10.2"
},
"dependencies": {
Expand Down