perf(forms): make `FormBuilder` class tree-shakable (#41126)
This commit makes the `FormBuilder` class tree-shakable by adding the `providedIn` property to its `@Injectable` decorator. Now if the `FormBuilder` class is not referenced in application's code, it should not be included into its production bundle. PR Close #41126
This commit is contained in:
parent
0093b3b19f
commit
b93fb79839
|
@ -9,6 +9,7 @@
|
|||
import {Injectable} from '@angular/core';
|
||||
|
||||
import {AsyncValidatorFn, ValidatorFn} from './directives/validators';
|
||||
import {ReactiveFormsModule} from './form_providers';
|
||||
import {AbstractControl, AbstractControlOptions, FormArray, FormControl, FormGroup, FormHooks} from './model';
|
||||
|
||||
function isAbstractControlOptions(options: AbstractControlOptions|
|
||||
|
@ -30,7 +31,7 @@ function isAbstractControlOptions(options: AbstractControlOptions|
|
|||
*
|
||||
* @publicApi
|
||||
*/
|
||||
@Injectable()
|
||||
@Injectable({providedIn: ReactiveFormsModule})
|
||||
export class FormBuilder {
|
||||
/**
|
||||
* @description
|
||||
|
|
|
@ -10,7 +10,6 @@ import {ModuleWithProviders, NgModule} from '@angular/core';
|
|||
|
||||
import {InternalFormsSharedModule, NG_MODEL_WITH_FORM_CONTROL_WARNING, REACTIVE_DRIVEN_DIRECTIVES, TEMPLATE_DRIVEN_DIRECTIVES} from './directives';
|
||||
import {RadioControlRegistry} from './directives/radio_control_value_accessor';
|
||||
import {FormBuilder} from './form_builder';
|
||||
|
||||
/**
|
||||
* Exports the required providers and directives for template-driven forms,
|
||||
|
@ -40,7 +39,9 @@ export class FormsModule {
|
|||
*/
|
||||
@NgModule({
|
||||
declarations: [REACTIVE_DRIVEN_DIRECTIVES],
|
||||
providers: [FormBuilder, RadioControlRegistry],
|
||||
// Note: FormBuilder is also provided in this module as a tree-shakable provider,
|
||||
// see packages/forms/src/form_builder.ts.
|
||||
providers: [RadioControlRegistry],
|
||||
exports: [InternalFormsSharedModule, REACTIVE_DRIVEN_DIRECTIVES]
|
||||
})
|
||||
export class ReactiveFormsModule {
|
||||
|
|
Loading…
Reference in New Issue