Skip to content

Commit 2bd0195

Browse files
eneufeldsdirix
authored andcommitted
Add Angular component config support
- add config input to Angular root component - use two way databinding in example for data Also fixes initial readonly value passing in the Angular root component.
1 parent a648f46 commit 2bd0195

File tree

3 files changed

+13
-51
lines changed

3 files changed

+13
-51
lines changed

packages/angular-material/example/app/app.component.ts

+3-7
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ const itemTester: UISchemaTester = (_schema, schemaPath, _path) => {
4949
selector: 'app-root',
5050
template: `
5151
<h1>Angular Material Examples</h1>
52-
Data: {{ data | json }}
52+
Data: {{ selectedExample.data | json }}
5353
<div>
5454
Example:
5555
<select (change)="onChange($event)">
@@ -71,14 +71,14 @@ const itemTester: UISchemaTester = (_schema, schemaPath, _path) => {
7171
</button>
7272
</div>
7373
<jsonforms
74-
[data]="selectedExample.data"
74+
[(data)]="selectedExample.data"
7575
[schema]="selectedExample.schema"
7676
[uischema]="selectedExample.uischema"
7777
[renderers]="renderers"
78-
(dataChange)="onDataChange($event)"
7978
[locale]="currentLocale"
8079
[uischemas]="uischemas"
8180
[readonly]="readonly"
81+
[config]="config"
8282
></jsonforms>
8383
`
8484
})
@@ -97,10 +97,6 @@ export class AppComponent {
9797
this.selectedExample = this.examples[19];
9898
}
9999

100-
onDataChange(data: any) {
101-
this.data = data;
102-
}
103-
104100
onChange(ev: any) {
105101
this.selectedExample = this.examples.find(e => e.name === ev.target.value);
106102
}

packages/angular-material/example/app/store.ts

-42
This file was deleted.

packages/angular/src/jsonforms-root.component.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import {
2626
Component,
2727
EventEmitter, Input, OnChanges, OnInit, Output, SimpleChanges
2828
} from '@angular/core';
29-
import { JsonFormsRendererRegistryEntry, JsonSchema, UISchemaElement, UISchemaTester, ValidationMode } from '@jsonforms/core';
29+
import { Actions, JsonFormsRendererRegistryEntry, JsonSchema, UISchemaElement, UISchemaTester, ValidationMode } from '@jsonforms/core';
3030
import { Ajv } from 'ajv';
3131
import { JsonFormsAngularService, USE_STATE_VALUE } from './jsonforms.service';
3232
@Component({
@@ -46,6 +46,7 @@ export class JsonForms implements OnChanges, OnInit {
4646
@Input() readonly: boolean;
4747
@Input() validationMode: ValidationMode;
4848
@Input() ajv: Ajv;
49+
@Input() config: any;
4950

5051
private initialized = false;
5152

@@ -63,7 +64,9 @@ export class JsonForms implements OnChanges, OnInit {
6364
},
6465
uischemas: this.uischemas,
6566
i18n: { locale: this.locale, localizedSchemas: undefined, localizedUISchemas: undefined },
66-
renderers: this.renderers
67+
renderers: this.renderers,
68+
config: this.config,
69+
readonly: this.readonly
6770
});
6871
this.jsonformsService.$state.subscribe(state => {
6972
const data = state?.jsonforms?.core?.data;
@@ -88,6 +91,7 @@ export class JsonForms implements OnChanges, OnInit {
8891
const newReadonly = changes.readonly;
8992
const newValidationMode = changes.validationMode;
9093
const newAjv = changes.ajv;
94+
const newConfig = changes.config;
9195

9296
if (newData || newSchema || newUiSchema || newValidationMode || newAjv) {
9397
this.jsonformsService.updateCoreState(
@@ -114,5 +118,9 @@ export class JsonForms implements OnChanges, OnInit {
114118
if (newReadonly && !newReadonly.isFirstChange()) {
115119
this.jsonformsService.setReadonly(newReadonly.currentValue);
116120
}
121+
122+
if (newConfig && !newConfig.isFirstChange()) {
123+
this.jsonformsService.updateConfig(Actions.setConfig(newConfig.currentValue));
124+
}
117125
}
118126
}

0 commit comments

Comments
 (0)