forked from angular/angular
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathform_providers.ts
More file actions
102 lines (98 loc) · 3.06 KB
/
form_providers.ts
File metadata and controls
102 lines (98 loc) · 3.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {ModuleWithProviders, NgModule} from '@angular/core';
import {
InternalFormsSharedModule,
NG_MODEL_WITH_FORM_CONTROL_WARNING,
REACTIVE_DRIVEN_DIRECTIVES,
TEMPLATE_DRIVEN_DIRECTIVES,
} from './directives';
import {
CALL_SET_DISABLED_STATE,
setDisabledStateDefault,
SetDisabledStateOption,
} from './directives/shared';
/**
* Exports the required providers and directives for template-driven forms,
* making them available for import by NgModules that import this module.
*
* @see [Forms Overview](guide/forms)
* @see [Template-driven Forms Guide](guide/forms)
*
* @publicApi
*/
@NgModule({
declarations: TEMPLATE_DRIVEN_DIRECTIVES,
exports: [InternalFormsSharedModule, TEMPLATE_DRIVEN_DIRECTIVES],
})
export class FormsModule {
/**
* @description
* Provides options for configuring the forms module.
*
* @param opts An object of configuration options
* * `callSetDisabledState` Configures whether to `always` call `setDisabledState`, which is more
* correct, or to only call it `whenDisabled`, which is the legacy behavior.
*/
static withConfig(opts: {
callSetDisabledState?: SetDisabledStateOption;
}): ModuleWithProviders<FormsModule> {
return {
ngModule: FormsModule,
providers: [
{
provide: CALL_SET_DISABLED_STATE,
useValue: opts.callSetDisabledState ?? setDisabledStateDefault,
},
],
};
}
}
/**
* Exports the required infrastructure and directives for reactive forms,
* making them available for import by NgModules that import this module.
*
* @see [Forms Overview](guide/forms)
* @see [Reactive Forms Guide](guide/forms/reactive-forms)
*
* @publicApi
*/
@NgModule({
declarations: [REACTIVE_DRIVEN_DIRECTIVES],
exports: [InternalFormsSharedModule, REACTIVE_DRIVEN_DIRECTIVES],
})
export class ReactiveFormsModule {
/**
* @description
* Provides options for configuring the reactive forms module.
*
* @param opts An object of configuration options
* * `warnOnNgModelWithFormControl` Configures when to emit a warning when an `ngModel`
* binding is used with reactive form directives.
* * `callSetDisabledState` Configures whether to `always` call `setDisabledState`, which is more
* correct, or to only call it `whenDisabled`, which is the legacy behavior.
*/
static withConfig(opts: {
/** @deprecated as of v6 */ warnOnNgModelWithFormControl?: 'never' | 'once' | 'always';
callSetDisabledState?: SetDisabledStateOption;
}): ModuleWithProviders<ReactiveFormsModule> {
return {
ngModule: ReactiveFormsModule,
providers: [
{
provide: NG_MODEL_WITH_FORM_CONTROL_WARNING,
useValue: opts.warnOnNgModelWithFormControl ?? 'always',
},
{
provide: CALL_SET_DISABLED_STATE,
useValue: opts.callSetDisabledState ?? setDisabledStateDefault,
},
],
};
}
}