Skip to content

Commit 6fc7c50

Browse files
authored
refactor(multiple): run typed forms migration (#24698)
Runs the typed forms migration over all our code.
1 parent b372f68 commit 6fc7c50

File tree

100 files changed

+453
-406
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+453
-406
lines changed

src/cdk-experimental/listbox/listbox.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
dispatchMouseEvent,
99
} from '../../cdk/testing/private';
1010
import {A, DOWN_ARROW, END, HOME, SPACE} from '@angular/cdk/keycodes';
11-
import {FormControl, FormsModule, ReactiveFormsModule} from '@angular/forms';
11+
import {UntypedFormControl, FormsModule, ReactiveFormsModule} from '@angular/forms';
1212
import {CdkCombobox, CdkComboboxModule} from '@angular/cdk-experimental/combobox';
1313

1414
describe('CdkOption and CdkListbox', () => {
@@ -967,7 +967,7 @@ class ListboxActiveDescendant {
967967
</select>`,
968968
})
969969
class ListboxControlValueAccessor {
970-
form = new FormControl();
970+
form = new UntypedFormControl();
971971
changedOption: CdkOption<string>;
972972
isDisabled: boolean = false;
973973
isMultiselectable: boolean = false;

src/cdk/testing/tests/test-main-component.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import {ENTER} from '@angular/cdk/keycodes';
1010
import {_supportsShadowDom} from '@angular/cdk/platform';
11-
import {FormControl} from '@angular/forms';
11+
import {UntypedFormControl} from '@angular/forms';
1212
import {
1313
ChangeDetectionStrategy,
1414
ChangeDetectorRef,
@@ -47,7 +47,7 @@ export class TestMainComponent implements OnDestroy {
4747
_shadowDomSupported = _supportsShadowDom();
4848
clickResult = {x: -1, y: -1};
4949
rightClickResult = {x: -1, y: -1, button: -1};
50-
numberControl = new FormControl();
50+
numberControl = new UntypedFormControl();
5151

5252
@ViewChild('clickTestElement') clickTestElement: ElementRef<HTMLElement>;
5353
@ViewChild('taskStateResult') taskStateResultElement: ElementRef<HTMLElement>;

src/components-examples/cdk/stepper/cdk-linear-stepper-with-form/cdk-linear-stepper-with-form-example.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {Component} from '@angular/core';
22
import {CdkStepper} from '@angular/cdk/stepper';
3-
import {FormBuilder, FormGroup, Validators} from '@angular/forms';
3+
import {UntypedFormBuilder, UntypedFormGroup, Validators} from '@angular/forms';
44

55
/** @title A custom CDK linear stepper with forms */
66
@Component({
@@ -10,10 +10,10 @@ import {FormBuilder, FormGroup, Validators} from '@angular/forms';
1010
})
1111
export class CdkLinearStepperWithFormExample {
1212
isLinear = true;
13-
firstFormGroup: FormGroup;
14-
secondFormGroup: FormGroup;
13+
firstFormGroup: UntypedFormGroup;
14+
secondFormGroup: UntypedFormGroup;
1515

16-
constructor(private readonly _formBuilder: FormBuilder) {
16+
constructor(private readonly _formBuilder: UntypedFormBuilder) {
1717
this.firstFormGroup = this._formBuilder.group({
1818
firstControl: ['', Validators.required],
1919
});

src/components-examples/material-experimental/mdc-form-field/mdc-form-field-custom-control/form-field-custom-control-example.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import {FocusMonitor} from '@angular/cdk/a11y';
22
import {BooleanInput, coerceBooleanProperty} from '@angular/cdk/coercion';
33
import {Component, ElementRef, Inject, Input, OnDestroy, Optional, Self} from '@angular/core';
4-
import {ControlValueAccessor, FormBuilder, FormGroup, NgControl, Validators} from '@angular/forms';
4+
import {
5+
ControlValueAccessor,
6+
UntypedFormBuilder,
7+
UntypedFormGroup,
8+
NgControl,
9+
Validators,
10+
} from '@angular/forms';
511
import {MatFormField, MatFormFieldControl} from '@angular/material-experimental/mdc-form-field';
612
import {MAT_FORM_FIELD} from '@angular/material/form-field';
713
import {Subject} from 'rxjs';
@@ -32,7 +38,7 @@ export class MyTel {
3238
export class MyTelInput implements ControlValueAccessor, MatFormFieldControl<MyTel>, OnDestroy {
3339
static nextId = 0;
3440

35-
parts: FormGroup;
41+
parts: UntypedFormGroup;
3642
stateChanges = new Subject<void>();
3743
focused = false;
3844
errorState = false;
@@ -103,7 +109,7 @@ export class MyTelInput implements ControlValueAccessor, MatFormFieldControl<MyT
103109
}
104110

105111
constructor(
106-
formBuilder: FormBuilder,
112+
formBuilder: UntypedFormBuilder,
107113
private _focusMonitor: FocusMonitor,
108114
private _elementRef: ElementRef<HTMLElement>,
109115
@Optional() @Inject(MAT_FORM_FIELD) public _formField: MatFormField,

src/components-examples/material/autocomplete/autocomplete-auto-active-first-option/autocomplete-auto-active-first-option-example.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {Component, OnInit} from '@angular/core';
2-
import {FormControl} from '@angular/forms';
2+
import {UntypedFormControl} from '@angular/forms';
33
import {Observable} from 'rxjs';
44
import {map, startWith} from 'rxjs/operators';
55

@@ -12,7 +12,7 @@ import {map, startWith} from 'rxjs/operators';
1212
styleUrls: ['autocomplete-auto-active-first-option-example.css'],
1313
})
1414
export class AutocompleteAutoActiveFirstOptionExample implements OnInit {
15-
myControl = new FormControl();
15+
myControl = new UntypedFormControl();
1616
options: string[] = ['One', 'Two', 'Three'];
1717
filteredOptions: Observable<string[]>;
1818

src/components-examples/material/autocomplete/autocomplete-display/autocomplete-display-example.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {Component, OnInit} from '@angular/core';
2-
import {FormControl} from '@angular/forms';
2+
import {UntypedFormControl} from '@angular/forms';
33
import {Observable} from 'rxjs';
44
import {map, startWith} from 'rxjs/operators';
55

@@ -16,7 +16,7 @@ export interface User {
1616
styleUrls: ['autocomplete-display-example.css'],
1717
})
1818
export class AutocompleteDisplayExample implements OnInit {
19-
myControl = new FormControl();
19+
myControl = new UntypedFormControl();
2020
options: User[] = [{name: 'Mary'}, {name: 'Shelley'}, {name: 'Igor'}];
2121
filteredOptions: Observable<User[]>;
2222

src/components-examples/material/autocomplete/autocomplete-filter/autocomplete-filter-example.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {Component, OnInit} from '@angular/core';
2-
import {FormControl} from '@angular/forms';
2+
import {UntypedFormControl} from '@angular/forms';
33
import {Observable} from 'rxjs';
44
import {map, startWith} from 'rxjs/operators';
55

@@ -12,7 +12,7 @@ import {map, startWith} from 'rxjs/operators';
1212
styleUrls: ['autocomplete-filter-example.css'],
1313
})
1414
export class AutocompleteFilterExample implements OnInit {
15-
myControl = new FormControl();
15+
myControl = new UntypedFormControl();
1616
options: string[] = ['One', 'Two', 'Three'];
1717
filteredOptions: Observable<string[]>;
1818

src/components-examples/material/autocomplete/autocomplete-optgroup/autocomplete-optgroup-example.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {Component, OnInit} from '@angular/core';
2-
import {FormBuilder, FormGroup} from '@angular/forms';
2+
import {UntypedFormBuilder, UntypedFormGroup} from '@angular/forms';
33
import {Observable} from 'rxjs';
44
import {startWith, map} from 'rxjs/operators';
55

@@ -22,7 +22,7 @@ export const _filter = (opt: string[], value: string): string[] => {
2222
templateUrl: 'autocomplete-optgroup-example.html',
2323
})
2424
export class AutocompleteOptgroupExample implements OnInit {
25-
stateForm: FormGroup = this._formBuilder.group({
25+
stateForm: UntypedFormGroup = this._formBuilder.group({
2626
stateGroup: '',
2727
});
2828

@@ -125,7 +125,7 @@ export class AutocompleteOptgroupExample implements OnInit {
125125

126126
stateGroupOptions: Observable<StateGroup[]>;
127127

128-
constructor(private _formBuilder: FormBuilder) {}
128+
constructor(private _formBuilder: UntypedFormBuilder) {}
129129

130130
ngOnInit() {
131131
this.stateGroupOptions = this.stateForm.get('stateGroup')!.valueChanges.pipe(

src/components-examples/material/autocomplete/autocomplete-overview/autocomplete-overview-example.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {Component} from '@angular/core';
2-
import {FormControl} from '@angular/forms';
2+
import {UntypedFormControl} from '@angular/forms';
33
import {Observable} from 'rxjs';
44
import {map, startWith} from 'rxjs/operators';
55

@@ -18,7 +18,7 @@ export interface State {
1818
styleUrls: ['autocomplete-overview-example.css'],
1919
})
2020
export class AutocompleteOverviewExample {
21-
stateCtrl = new FormControl();
21+
stateCtrl = new UntypedFormControl();
2222
filteredStates: Observable<State[]>;
2323

2424
states: State[] = [

src/components-examples/material/autocomplete/autocomplete-plain-input/autocomplete-plain-input-example.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {Component, OnInit} from '@angular/core';
2-
import {FormControl} from '@angular/forms';
2+
import {UntypedFormControl} from '@angular/forms';
33
import {Observable} from 'rxjs';
44
import {startWith, map} from 'rxjs/operators';
55

@@ -12,7 +12,7 @@ import {startWith, map} from 'rxjs/operators';
1212
styleUrls: ['autocomplete-plain-input-example.css'],
1313
})
1414
export class AutocompletePlainInputExample implements OnInit {
15-
control = new FormControl();
15+
control = new UntypedFormControl();
1616
streets: string[] = ['Champs-Élysées', 'Lombard Street', 'Abbey Road', 'Fifth Avenue'];
1717
filteredStreets: Observable<string[]>;
1818

src/components-examples/material/autocomplete/autocomplete-simple/autocomplete-simple-example.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {Component} from '@angular/core';
2-
import {FormControl} from '@angular/forms';
2+
import {UntypedFormControl} from '@angular/forms';
33

44
/**
55
* @title Simple autocomplete
@@ -10,6 +10,6 @@ import {FormControl} from '@angular/forms';
1010
styleUrls: ['autocomplete-simple-example.css'],
1111
})
1212
export class AutocompleteSimpleExample {
13-
myControl = new FormControl();
13+
myControl = new UntypedFormControl();
1414
options: string[] = ['One', 'Two', 'Three'];
1515
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {Component} from '@angular/core';
2-
import {FormControl} from '@angular/forms';
2+
import {UntypedFormControl} from '@angular/forms';
33

44
/**
55
* @title Button-toggles with forms
@@ -9,6 +9,6 @@ import {FormControl} from '@angular/forms';
99
templateUrl: 'button-toggle-forms-example.html',
1010
})
1111
export class ButtonToggleFormsExample {
12-
fontStyleControl = new FormControl();
12+
fontStyleControl = new UntypedFormControl();
1313
fontStyle?: string;
1414
}

src/components-examples/material/checkbox/checkbox-reactive-forms/checkbox-reactive-forms-example.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {Component} from '@angular/core';
2-
import {FormBuilder, FormGroup} from '@angular/forms';
2+
import {UntypedFormBuilder, UntypedFormGroup} from '@angular/forms';
33

44
/** @title Checkboxes with reactive forms */
55
@Component({
@@ -8,9 +8,9 @@ import {FormBuilder, FormGroup} from '@angular/forms';
88
styleUrls: ['checkbox-reactive-forms-example.css'],
99
})
1010
export class CheckboxReactiveFormsExample {
11-
toppings: FormGroup;
11+
toppings: UntypedFormGroup;
1212

13-
constructor(fb: FormBuilder) {
13+
constructor(fb: UntypedFormBuilder) {
1414
this.toppings = fb.group({
1515
pepperoni: false,
1616
extracheese: false,

src/components-examples/material/chips/chips-autocomplete/chips-autocomplete-example.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {COMMA, ENTER} from '@angular/cdk/keycodes';
22
import {Component, ElementRef, ViewChild} from '@angular/core';
3-
import {FormControl} from '@angular/forms';
3+
import {UntypedFormControl} from '@angular/forms';
44
import {MatAutocompleteSelectedEvent} from '@angular/material/autocomplete';
55
import {MatChipInputEvent} from '@angular/material/chips';
66
import {Observable} from 'rxjs';
@@ -16,7 +16,7 @@ import {map, startWith} from 'rxjs/operators';
1616
})
1717
export class ChipsAutocompleteExample {
1818
separatorKeysCodes: number[] = [ENTER, COMMA];
19-
fruitCtrl = new FormControl();
19+
fruitCtrl = new UntypedFormControl();
2020
filteredFruits: Observable<string[]>;
2121
fruits: string[] = ['Lemon'];
2222
allFruits: string[] = ['Apple', 'Lemon', 'Lime', 'Orange', 'Strawberry'];

src/components-examples/material/chips/chips-form-control/chips-form-control-example.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {Component} from '@angular/core';
2-
import {FormControl} from '@angular/forms';
2+
import {UntypedFormControl} from '@angular/forms';
33
import {MatChipInputEvent} from '@angular/material/chips';
44

55
/**
@@ -12,7 +12,7 @@ import {MatChipInputEvent} from '@angular/material/chips';
1212
})
1313
export class ChipsFormControlExample {
1414
keywords = new Set(['angular', 'how-to', 'tutorial']);
15-
formControl = new FormControl(['angular']);
15+
formControl = new UntypedFormControl(['angular']);
1616

1717
addKeywordFromInput(event: MatChipInputEvent) {
1818
if (event.value) {
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {Component} from '@angular/core';
2-
import {FormGroup, FormControl} from '@angular/forms';
2+
import {UntypedFormGroup, UntypedFormControl} from '@angular/forms';
33

44
/** @title Date range picker comparison ranges */
55
@Component({
@@ -8,22 +8,22 @@ import {FormGroup, FormControl} from '@angular/forms';
88
styleUrls: ['date-range-picker-comparison-example.css'],
99
})
1010
export class DateRangePickerComparisonExample {
11-
campaignOne: FormGroup;
12-
campaignTwo: FormGroup;
11+
campaignOne: UntypedFormGroup;
12+
campaignTwo: UntypedFormGroup;
1313

1414
constructor() {
1515
const today = new Date();
1616
const month = today.getMonth();
1717
const year = today.getFullYear();
1818

19-
this.campaignOne = new FormGroup({
20-
start: new FormControl(new Date(year, month, 13)),
21-
end: new FormControl(new Date(year, month, 16)),
19+
this.campaignOne = new UntypedFormGroup({
20+
start: new UntypedFormControl(new Date(year, month, 13)),
21+
end: new UntypedFormControl(new Date(year, month, 16)),
2222
});
2323

24-
this.campaignTwo = new FormGroup({
25-
start: new FormControl(new Date(year, month, 15)),
26-
end: new FormControl(new Date(year, month, 19)),
24+
this.campaignTwo = new UntypedFormGroup({
25+
start: new UntypedFormControl(new Date(year, month, 15)),
26+
end: new UntypedFormControl(new Date(year, month, 19)),
2727
});
2828
}
2929
}
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import {Component} from '@angular/core';
2-
import {FormGroup, FormControl} from '@angular/forms';
2+
import {UntypedFormGroup, UntypedFormControl} from '@angular/forms';
33

44
/** @title Date range picker forms integration */
55
@Component({
66
selector: 'date-range-picker-forms-example',
77
templateUrl: 'date-range-picker-forms-example.html',
88
})
99
export class DateRangePickerFormsExample {
10-
range = new FormGroup({
11-
start: new FormControl(),
12-
end: new FormControl(),
10+
range = new UntypedFormGroup({
11+
start: new UntypedFormControl(),
12+
end: new UntypedFormControl(),
1313
});
1414
}

src/components-examples/material/datepicker/datepicker-formats/datepicker-formats-example.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {Component} from '@angular/core';
2-
import {FormControl} from '@angular/forms';
2+
import {UntypedFormControl} from '@angular/forms';
33
import {MomentDateAdapter, MAT_MOMENT_DATE_ADAPTER_OPTIONS} from '@angular/material-moment-adapter';
44
import {DateAdapter, MAT_DATE_FORMATS, MAT_DATE_LOCALE} from '@angular/material/core';
55

@@ -45,5 +45,5 @@ export const MY_FORMATS = {
4545
],
4646
})
4747
export class DatepickerFormatsExample {
48-
date = new FormControl(moment());
48+
date = new UntypedFormControl(moment());
4949
}

src/components-examples/material/datepicker/datepicker-moment/datepicker-moment-example.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {Component} from '@angular/core';
2-
import {FormControl} from '@angular/forms';
2+
import {UntypedFormControl} from '@angular/forms';
33
import {MAT_MOMENT_DATE_FORMATS, MomentDateAdapter} from '@angular/material-moment-adapter';
44
import {DateAdapter, MAT_DATE_FORMATS, MAT_DATE_LOCALE} from '@angular/material/core';
55

@@ -27,5 +27,5 @@ const moment = _rollupMoment || _moment;
2727
})
2828
export class DatepickerMomentExample {
2929
// Datepicker takes `Moment` objects instead of `Date` objects.
30-
date = new FormControl(moment([2017, 0, 1]));
30+
date = new UntypedFormControl(moment([2017, 0, 1]));
3131
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {Component} from '@angular/core';
2-
import {FormControl} from '@angular/forms';
2+
import {UntypedFormControl} from '@angular/forms';
33

44
/** @title Datepicker selected value */
55
@Component({
@@ -8,6 +8,6 @@ import {FormControl} from '@angular/forms';
88
styleUrls: ['datepicker-value-example.css'],
99
})
1010
export class DatepickerValueExample {
11-
date = new FormControl(new Date());
12-
serializedDate = new FormControl(new Date().toISOString());
11+
date = new UntypedFormControl(new Date());
12+
serializedDate = new UntypedFormControl(new Date().toISOString());
1313
}

src/components-examples/material/datepicker/datepicker-views-selection/datepicker-views-selection-example.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {Component} from '@angular/core';
2-
import {FormControl} from '@angular/forms';
2+
import {UntypedFormControl} from '@angular/forms';
33
import {MomentDateAdapter, MAT_MOMENT_DATE_ADAPTER_OPTIONS} from '@angular/material-moment-adapter';
44
import {DateAdapter, MAT_DATE_FORMATS, MAT_DATE_LOCALE} from '@angular/material/core';
55
import {MatDatepicker} from '@angular/material/datepicker';
@@ -47,7 +47,7 @@ export const MY_FORMATS = {
4747
],
4848
})
4949
export class DatepickerViewsSelectionExample {
50-
date = new FormControl(moment());
50+
date = new UntypedFormControl(moment());
5151

5252
setMonthAndYear(normalizedMonthAndYear: Moment, datepicker: MatDatepicker<Moment>) {
5353
const ctrlValue = this.date.value;

0 commit comments

Comments
 (0)