Skip to content

Commit 2eb83c2

Browse files
committed
WIP: angular: Migrate to standalone components
Starting with Angular 19, standalone components are the new default and non-standalone components are discouraged producing a lint error. This migrates all components of the Angular and Angular Material packages to be standalone. Backwards compatibility is maintained by keeping existing NG modules which now import and export all components. Thus, users can use the modules as before. DEV Notes: - Tested with angular seed => worked well - Needs careful code review
1 parent 7130eda commit 2eb83c2

38 files changed

+223
-103
lines changed

packages/angular-material/.eslintrc.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ module.exports = {
2222
'@angular-eslint/component-class-suffix': 'off',
2323
'@angular-eslint/directive-class-suffix': 'off',
2424
'@angular-eslint/no-conflicting-lifecycle': 'warn',
25-
// Starting with Angular 19, non-standalone components produce a lint error. Reduce to warning until we migrate.
26-
'@angular-eslint/prefer-standalone': 'warn',
2725
'@typescript-eslint/no-explicit-any': 'off',
2826
// Base rule must be disabled to avoid incorrect errors
2927
'no-unused-vars': 'off',

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
THE SOFTWARE.
2424
*/
2525
import { Component } from '@angular/core';
26+
import { CommonModule } from '@angular/common';
27+
import { JsonFormsModule } from '@jsonforms/angular';
2628
import { ExampleDescription, getExamples } from '@jsonforms/examples';
2729
import {
2830
JsonFormsI18nState,
@@ -87,7 +89,7 @@ const itemTester: UISchemaTester = (_schema, schemaPath, _path) => {
8789
[readonly]="readonly"
8890
></jsonforms>
8991
`,
90-
standalone: false,
92+
imports: [CommonModule, JsonFormsModule],
9193
})
9294
export class AppComponent {
9395
readonly renderers = angularMaterialRenderers;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ import { AppComponent } from './app.component';
2929
import { JsonFormsAngularMaterialModule } from '../../src/library';
3030

3131
@NgModule({
32-
declarations: [AppComponent],
3332
imports: [
3433
BrowserModule,
3534
BrowserAnimationsModule,
3635
JsonFormsAngularMaterialModule,
36+
AppComponent,
3737
],
3838
bootstrap: [AppComponent],
3939
schemas: [CUSTOM_ELEMENTS_SCHEMA],

packages/angular-material/src/library/controls/autocomplete.renderer.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ import {
4141
} from '@jsonforms/core';
4242
import type { Observable } from 'rxjs';
4343
import { map, startWith } from 'rxjs/operators';
44+
import { CommonModule } from '@angular/common';
45+
import { ReactiveFormsModule } from '@angular/forms';
46+
import { MatFormFieldModule } from '@angular/material/form-field';
47+
import { MatInputModule } from '@angular/material/input';
48+
import { MatAutocompleteModule } from '@angular/material/autocomplete';
4449

4550
/**
4651
* To use this component you will need to add your own tester:
@@ -110,7 +115,13 @@ import { map, startWith } from 'rxjs/operators';
110115
`,
111116
],
112117
changeDetection: ChangeDetectionStrategy.OnPush,
113-
standalone: false,
118+
imports: [
119+
CommonModule,
120+
ReactiveFormsModule,
121+
MatFormFieldModule,
122+
MatInputModule,
123+
MatAutocompleteModule,
124+
],
114125
})
115126
export class AutocompleteControlRenderer
116127
extends JsonFormsControl

packages/angular-material/src/library/controls/boolean.renderer.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ import {
3030
} from '@angular/core';
3131
import { JsonFormsAngularService, JsonFormsControl } from '@jsonforms/angular';
3232
import { isBooleanControl, RankedTester, rankWith } from '@jsonforms/core';
33+
import { CommonModule } from '@angular/common';
34+
import { MatCheckboxModule } from '@angular/material/checkbox';
35+
import { MatFormFieldModule } from '@angular/material/form-field';
3336

3437
@Component({
3538
selector: 'BooleanControlRenderer',
@@ -65,7 +68,7 @@ import { isBooleanControl, RankedTester, rankWith } from '@jsonforms/core';
6568
`,
6669
],
6770
changeDetection: ChangeDetectionStrategy.OnPush,
68-
standalone: false,
71+
imports: [CommonModule, MatCheckboxModule, MatFormFieldModule],
6972
})
7073
export class BooleanControlRenderer extends JsonFormsControl {
7174
constructor(

packages/angular-material/src/library/controls/date.renderer.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,14 @@ import { JsonFormsAngularService, JsonFormsControl } from '@jsonforms/angular';
4040
import { DateAdapter, MAT_DATE_FORMATS } from '@angular/material/core';
4141
import { MyFormat } from '../util/date-format';
4242
import { DayJsDateAdapter } from '../util/dayjs-date-adapter';
43-
import { MatDatepicker } from '@angular/material/datepicker';
43+
import {
44+
MatDatepicker,
45+
MatDatepickerModule,
46+
} from '@angular/material/datepicker';
47+
import { CommonModule } from '@angular/common';
48+
import { ReactiveFormsModule } from '@angular/forms';
49+
import { MatFormFieldModule } from '@angular/material/form-field';
50+
import { MatInputModule } from '@angular/material/input';
4451

4552
@Component({
4653
selector: 'DateControlRenderer',
@@ -105,7 +112,13 @@ import { MatDatepicker } from '@angular/material/datepicker';
105112
useClass: MyFormat,
106113
},
107114
],
108-
standalone: false,
115+
imports: [
116+
CommonModule,
117+
ReactiveFormsModule,
118+
MatFormFieldModule,
119+
MatInputModule,
120+
MatDatepickerModule,
121+
],
109122
})
110123
export class DateControlRenderer extends JsonFormsControl {
111124
focused = false;

packages/angular-material/src/library/controls/number.renderer.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ import {
3333
StatePropsOfControl,
3434
} from '@jsonforms/core';
3535
import merge from 'lodash/merge';
36+
import { CommonModule } from '@angular/common';
37+
import { ReactiveFormsModule } from '@angular/forms';
38+
import { MatFormFieldModule } from '@angular/material/form-field';
39+
import { MatInputModule } from '@angular/material/input';
3640

3741
@Component({
3842
selector: 'NumberControlRenderer',
@@ -69,7 +73,12 @@ import merge from 'lodash/merge';
6973
`,
7074
],
7175
changeDetection: ChangeDetectionStrategy.OnPush,
72-
standalone: false,
76+
imports: [
77+
CommonModule,
78+
ReactiveFormsModule,
79+
MatFormFieldModule,
80+
MatInputModule,
81+
],
7382
})
7483
export class NumberControlRenderer extends JsonFormsControl {
7584
private readonly MAXIMUM_FRACTIONAL_DIGITS = 20;

packages/angular-material/src/library/controls/range.renderer.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ import {
2929
} from '@angular/core';
3030
import { JsonFormsAngularService, JsonFormsControl } from '@jsonforms/angular';
3131
import { isRangeControl, RankedTester, rankWith } from '@jsonforms/core';
32+
import { CommonModule } from '@angular/common';
33+
import { MatSliderModule } from '@angular/material/slider';
34+
import { MatFormFieldModule } from '@angular/material/form-field';
3235

3336
@Component({
3437
selector: 'RangeControlRenderer',
@@ -69,7 +72,7 @@ import { isRangeControl, RankedTester, rankWith } from '@jsonforms/core';
6972
`,
7073
],
7174
changeDetection: ChangeDetectionStrategy.OnPush,
72-
standalone: false,
75+
imports: [CommonModule, MatSliderModule, MatFormFieldModule],
7376
})
7477
export class RangeControlRenderer extends JsonFormsControl {
7578
min: number;

packages/angular-material/src/library/controls/text.renderer.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
import { ChangeDetectionStrategy, Component } from '@angular/core';
2626
import { JsonFormsAngularService, JsonFormsControl } from '@jsonforms/angular';
2727
import { isStringControl, RankedTester, rankWith } from '@jsonforms/core';
28+
import { CommonModule } from '@angular/common';
29+
import { ReactiveFormsModule } from '@angular/forms';
30+
import { MatFormFieldModule } from '@angular/material/form-field';
31+
import { MatInputModule } from '@angular/material/input';
2832

2933
@Component({
3034
selector: 'TextControlRenderer',
@@ -58,7 +62,12 @@ import { isStringControl, RankedTester, rankWith } from '@jsonforms/core';
5862
`,
5963
],
6064
changeDetection: ChangeDetectionStrategy.OnPush,
61-
standalone: false,
65+
imports: [
66+
CommonModule,
67+
ReactiveFormsModule,
68+
MatFormFieldModule,
69+
MatInputModule,
70+
],
6271
})
6372
export class TextControlRenderer extends JsonFormsControl {
6473
focused = false;

packages/angular-material/src/library/controls/textarea.renderer.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
import { ChangeDetectionStrategy, Component } from '@angular/core';
2626
import { JsonFormsAngularService, JsonFormsControl } from '@jsonforms/angular';
2727
import { isMultiLineControl, RankedTester, rankWith } from '@jsonforms/core';
28+
import { CommonModule } from '@angular/common';
29+
import { ReactiveFormsModule } from '@angular/forms';
30+
import { MatFormFieldModule } from '@angular/material/form-field';
31+
import { MatInputModule } from '@angular/material/input';
2832

2933
@Component({
3034
selector: 'TextAreaRenderer',
@@ -57,7 +61,12 @@ import { isMultiLineControl, RankedTester, rankWith } from '@jsonforms/core';
5761
`,
5862
],
5963
changeDetection: ChangeDetectionStrategy.OnPush,
60-
standalone: false,
64+
imports: [
65+
CommonModule,
66+
ReactiveFormsModule,
67+
MatFormFieldModule,
68+
MatInputModule,
69+
],
6170
})
6271
export class TextAreaRenderer extends JsonFormsControl {
6372
focused = false;

0 commit comments

Comments
 (0)