Skip to content

Commit 147a077

Browse files
committed
feat: remove the need for forRoot on material NgModules
1 parent d4ab3d3 commit 147a077

Some content is hidden

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

45 files changed

+367
-81
lines changed

src/lib/autocomplete/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export * from './autocomplete-trigger';
1515
declarations: [MdAutocomplete, MdAutocompleteTrigger],
1616
})
1717
export class MdAutocompleteModule {
18+
/** @deprecated */
1819
static forRoot(): ModuleWithProviders {
1920
return {
2021
ngModule: MdAutocompleteModule,

src/lib/button-toggle/button-toggle.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
UniqueSelectionDispatcher,
2525
coerceBooleanProperty,
2626
DefaultStyleCompatibilityModeModule,
27+
UNIQUE_SELECTION_DISPATCHER_PROVIDER,
2728
} from '../core';
2829

2930
/** Acceptable types for a button toggle. */
@@ -463,12 +464,14 @@ export class MdButtonToggle implements OnInit {
463464
DefaultStyleCompatibilityModeModule,
464465
],
465466
declarations: [MdButtonToggleGroup, MdButtonToggleGroupMultiple, MdButtonToggle],
467+
providers: [UNIQUE_SELECTION_DISPATCHER_PROVIDER]
466468
})
467469
export class MdButtonToggleModule {
470+
/** @deprecated */
468471
static forRoot(): ModuleWithProviders {
469472
return {
470473
ngModule: MdButtonToggleModule,
471-
providers: [UniqueSelectionDispatcher]
474+
providers: []
472475
};
473476
}
474477
}

src/lib/button/button.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
} from '@angular/core';
1212
import {CommonModule} from '@angular/common';
1313
import {MdRippleModule, coerceBooleanProperty, DefaultStyleCompatibilityModeModule} from '../core';
14-
import {ViewportRuler} from '../core/overlay/position/viewport-ruler';
1514

1615

1716
// TODO(jelbourn): Make the `isMouseDown` stuff done with one global listener.
@@ -167,10 +166,11 @@ export class MdAnchor extends MdButton {
167166
declarations: [MdButton, MdAnchor],
168167
})
169168
export class MdButtonModule {
169+
/** @deprecated */
170170
static forRoot(): ModuleWithProviders {
171171
return {
172172
ngModule: MdButtonModule,
173-
providers: [ViewportRuler]
173+
providers: []
174174
};
175175
}
176176
}

src/lib/card/card.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ export class MdCardTitleGroup {}
119119
],
120120
})
121121
export class MdCardModule {
122+
/** @deprecated */
122123
static forRoot(): ModuleWithProviders {
123124
return {
124125
ngModule: MdCardModule,

src/lib/checkbox/checkbox.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import {CommonModule} from '@angular/common';
1717
import {NG_VALUE_ACCESSOR, ControlValueAccessor} from '@angular/forms';
1818
import {coerceBooleanProperty} from '../core/coercion/boolean-property';
1919
import {MdRippleModule, DefaultStyleCompatibilityModeModule} from '../core';
20-
import {ViewportRuler} from '../core/overlay/position/viewport-ruler';
2120

2221

2322
/** Monotonically increasing integer used to auto-generate unique ids for checkbox components. */
@@ -399,10 +398,11 @@ export class MdCheckbox implements ControlValueAccessor {
399398
declarations: [MdCheckbox],
400399
})
401400
export class MdCheckboxModule {
401+
/** @deprecated */
402402
static forRoot(): ModuleWithProviders {
403403
return {
404404
ngModule: MdCheckboxModule,
405-
providers: [ViewportRuler]
405+
providers: []
406406
};
407407
}
408408
}

src/lib/chips/chip-list.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ export class MdChipList implements AfterContentInit {
215215
declarations: [MdChipList, MdChip]
216216
})
217217
export class MdChipsModule {
218+
/** @deprecated */
218219
static forRoot(): ModuleWithProviders {
219220
return {
220221
ngModule: MdChipsModule,

src/lib/core/a11y/index.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,22 @@
11
import {NgModule, ModuleWithProviders} from '@angular/core';
22
import {FocusTrap} from './focus-trap';
3-
import {LiveAnnouncer} from './live-announcer';
3+
import {LIVE_ANNOUNCER_PROVIDER} from './live-announcer';
44
import {InteractivityChecker} from './interactivity-checker';
55
import {CommonModule} from '@angular/common';
66
import {PlatformModule} from '../platform/index';
77

8-
export const A11Y_PROVIDERS = [LiveAnnouncer, InteractivityChecker];
9-
108
@NgModule({
119
imports: [CommonModule, PlatformModule],
1210
declarations: [FocusTrap],
1311
exports: [FocusTrap],
12+
providers: [InteractivityChecker, LIVE_ANNOUNCER_PROVIDER]
1413
})
1514
export class A11yModule {
15+
/** @deprecated */
1616
static forRoot(): ModuleWithProviders {
1717
return {
1818
ngModule: A11yModule,
19-
providers: [
20-
PlatformModule.forRoot().providers,
21-
A11Y_PROVIDERS,
22-
],
19+
providers: [],
2320
};
2421
}
2522
}

src/lib/core/a11y/live-announcer.spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,3 @@ class TestApp {
115115
this.live.announce(message);
116116
}
117117
}
118-

src/lib/core/a11y/live-announcer.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import {
22
Injectable,
33
OpaqueToken,
44
Optional,
5-
Inject
5+
Inject,
6+
SkipSelf,
67
} from '@angular/core';
78

89
export const LIVE_ANNOUNCER_ELEMENT_TOKEN = new OpaqueToken('liveAnnouncerElement');
@@ -62,3 +63,17 @@ export class LiveAnnouncer {
6263
}
6364

6465
}
66+
67+
export function LIVE_ANNOUNCER_PROVIDER_FACTORY(parentDispatcher: LiveAnnouncer, liveElement: any) {
68+
return parentDispatcher || new LiveAnnouncer(liveElement);
69+
};
70+
71+
export const LIVE_ANNOUNCER_PROVIDER = {
72+
// If there is already a LiveAnnouncer available, use that. Otherwise, provide a new one.
73+
provide: LiveAnnouncer,
74+
deps: [
75+
[new Optional(), new SkipSelf(), LiveAnnouncer],
76+
[new Optional(), new Inject(LIVE_ANNOUNCER_ELEMENT_TOKEN)]
77+
],
78+
useFactory: LIVE_ANNOUNCER_PROVIDER_FACTORY
79+
};

src/lib/core/compatibility/default-mode.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ export class MatPrefixEnforcer {
7171
}]
7272
})
7373
export class DefaultStyleCompatibilityModeModule {
74+
/** @deprecated */
7475
static forRoot(): ModuleWithProviders {
7576
return {
7677
ngModule: DefaultStyleCompatibilityModeModule,

0 commit comments

Comments
 (0)