Skip to content

Commit 2fd1e88

Browse files
committed
fix(forms): suppress forms deprecation warning after first
1 parent 17f317d commit 2fd1e88

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

modules/@angular/common/src/forms-deprecated/directives/ng_form.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import {composeAsyncValidators, composeValidators, setUpControl, setUpControlGro
1515
export const formDirectiveProvider: any =
1616
/*@ts2dart_const*/ {provide: ControlContainer, useExisting: forwardRef(() => NgForm)};
1717

18+
let _formWarningDisplayed: boolean = false;
19+
1820
/**
1921
* If `NgForm` is bound in a component, `<form>` elements in that component will be
2022
* upgraded to use the Angular form system.
@@ -76,6 +78,7 @@ export const formDirectiveProvider: any =
7678
*
7779
* @experimental
7880
*/
81+
7982
@Directive({
8083
selector: 'form:not([ngNoForm]):not([ngFormModel]),ngForm,[ngForm]',
8184
providers: [formDirectiveProvider],
@@ -95,13 +98,21 @@ export class NgForm extends ControlContainer implements Form {
9598
@Optional() @Self() @Inject(NG_VALIDATORS) validators: any[],
9699
@Optional() @Self() @Inject(NG_ASYNC_VALIDATORS) asyncValidators: any[]) {
97100
super();
98-
console.warn(`
101+
this._displayWarning();
102+
this.form = new ControlGroup(
103+
{}, null, composeValidators(validators), composeAsyncValidators(asyncValidators));
104+
}
105+
106+
private _displayWarning() {
107+
// TODO(kara): Update this when the new forms module becomes the default
108+
if (!_formWarningDisplayed) {
109+
_formWarningDisplayed = true;
110+
console.warn(`
99111
*It looks like you're using the old forms module. This will be opt-in in the next RC, and
100112
will eventually be removed in favor of the new forms module. For more information, see:
101113
https://docs.google.com/document/u/1/d/1RIezQqE4aEhBRmArIAS1mRIZtWFf6JxN_7B4meyWK0Y/pub
102114
`);
103-
this.form = new ControlGroup(
104-
{}, null, composeValidators(validators), composeAsyncValidators(asyncValidators));
115+
}
105116
}
106117

107118
get submitted(): boolean { return this._submitted; }

modules/@angular/common/src/forms-deprecated/directives/ng_form_model.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ export const formDirectiveProvider: any =
1919
useExisting: forwardRef(() => NgFormModel)
2020
};
2121

22+
let _formModelWarningDisplayed: boolean = false;
23+
2224
/**
2325
* Binds an existing control group to a DOM element.
2426
*
@@ -93,6 +95,7 @@ export const formDirectiveProvider: any =
9395
*
9496
* @experimental
9597
*/
98+
9699
@Directive({
97100
selector: '[ngFormModel]',
98101
providers: [formDirectiveProvider],
@@ -113,11 +116,19 @@ export class NgFormModel extends ControlContainer implements Form,
113116
@Optional() @Self() @Inject(NG_VALIDATORS) private _validators: any[],
114117
@Optional() @Self() @Inject(NG_ASYNC_VALIDATORS) private _asyncValidators: any[]) {
115118
super();
116-
console.warn(`
119+
this._displayWarning();
120+
}
121+
122+
private _displayWarning() {
123+
// TODO(kara): Update this when the new forms module becomes the default
124+
if (!_formModelWarningDisplayed) {
125+
_formModelWarningDisplayed = true;
126+
console.warn(`
117127
*It looks like you're using the old forms module. This will be opt-in in the next RC, and
118128
will eventually be removed in favor of the new forms module. For more information, see:
119129
https://docs.google.com/document/u/1/d/1RIezQqE4aEhBRmArIAS1mRIZtWFf6JxN_7B4meyWK0Y/pub
120130
`);
131+
}
121132
}
122133

123134
ngOnChanges(changes: SimpleChanges): void {

0 commit comments

Comments
 (0)