Skip to content

Commit b93fb79

Browse files
AndrewKushnirthePunderWoman
authored andcommitted
perf(forms): make FormBuilder class tree-shakable (angular#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 angular#41126
1 parent 0093b3b commit b93fb79

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

packages/forms/src/form_builder.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import {Injectable} from '@angular/core';
1010

1111
import {AsyncValidatorFn, ValidatorFn} from './directives/validators';
12+
import {ReactiveFormsModule} from './form_providers';
1213
import {AbstractControl, AbstractControlOptions, FormArray, FormControl, FormGroup, FormHooks} from './model';
1314

1415
function isAbstractControlOptions(options: AbstractControlOptions|
@@ -30,7 +31,7 @@ function isAbstractControlOptions(options: AbstractControlOptions|
3031
*
3132
* @publicApi
3233
*/
33-
@Injectable()
34+
@Injectable({providedIn: ReactiveFormsModule})
3435
export class FormBuilder {
3536
/**
3637
* @description

packages/forms/src/form_providers.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {ModuleWithProviders, NgModule} from '@angular/core';
1010

1111
import {InternalFormsSharedModule, NG_MODEL_WITH_FORM_CONTROL_WARNING, REACTIVE_DRIVEN_DIRECTIVES, TEMPLATE_DRIVEN_DIRECTIVES} from './directives';
1212
import {RadioControlRegistry} from './directives/radio_control_value_accessor';
13-
import {FormBuilder} from './form_builder';
1413

1514
/**
1615
* Exports the required providers and directives for template-driven forms,
@@ -40,7 +39,9 @@ export class FormsModule {
4039
*/
4140
@NgModule({
4241
declarations: [REACTIVE_DRIVEN_DIRECTIVES],
43-
providers: [FormBuilder, RadioControlRegistry],
42+
// Note: FormBuilder is also provided in this module as a tree-shakable provider,
43+
// see packages/forms/src/form_builder.ts.
44+
providers: [RadioControlRegistry],
4445
exports: [InternalFormsSharedModule, REACTIVE_DRIVEN_DIRECTIVES]
4546
})
4647
export class ReactiveFormsModule {

0 commit comments

Comments
 (0)