Skip to content

Commit 9ff6196

Browse files
authored
feat(modules): add forRoot to material modules (#1122)
1 parent 2c0dfcb commit 9ff6196

Some content is hidden

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

41 files changed

+212
-181
lines changed

src/demo-app/demo-app-module.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ import {TabsDemo} from './tabs/tab-group-demo';
3939
BrowserModule,
4040
FormsModule,
4141
HttpModule,
42-
MaterialModule,
43-
RouterModule.forRoot(DEMO_APP_ROUTES)
42+
RouterModule.forRoot(DEMO_APP_ROUTES),
43+
MaterialModule.forRoot(),
4444
],
4545
declarations: [
4646
BaselineDemo,

src/demo-app/dialog/dialog-demo.ts

-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import {Component, ViewContainerRef} from '@angular/core';
22
import {MdDialog, MdDialogConfig, MdDialogRef} from '@angular2-material/dialog/dialog';
3-
import {OVERLAY_PROVIDERS} from '@angular2-material/core/overlay/overlay';
43

54
@Component({
65
moduleId: module.id,
76
selector: 'dialog-demo',
87
templateUrl: 'dialog-demo.html',
98
styleUrls: ['dialog-demo.css'],
10-
providers: [MdDialog, OVERLAY_PROVIDERS]
119
})
1210
export class DialogDemo {
1311
dialogRef: MdDialogRef<JazzDialog>;

src/demo-app/overlay/overlay-demo.ts

-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010
Overlay,
1111
OverlayState,
1212
OverlayOrigin,
13-
OVERLAY_PROVIDERS,
1413
ComponentPortal,
1514
Portal,
1615
TemplatePortalDirective,
@@ -22,7 +21,6 @@ import {
2221
selector: 'overlay-demo',
2322
templateUrl: 'overlay-demo.html',
2423
styleUrls: ['overlay-demo.css'],
25-
providers: [OVERLAY_PROVIDERS],
2624
encapsulation: ViewEncapsulation.None,
2725
})
2826
export class OverlayDemo {

src/e2e-app/e2e-app-module.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import {E2E_APP_ROUTES} from './e2e-app/routes';
1313
@NgModule({
1414
imports: [
1515
BrowserModule,
16-
MaterialModule,
1716
RouterModule.forRoot(E2E_APP_ROUTES),
17+
MaterialModule.forRoot(),
1818
],
1919
declarations: [
2020
E2EApp,

src/lib/all/all.ts

+40-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {NgModule} from '@angular/core';
1+
import {NgModule, ModuleWithProviders} from '@angular/core';
22
import {MdButtonToggleModule} from '@angular2-material/button-toggle/button-toggle';
33
import {MdButtonModule} from '@angular2-material/button/button';
44
import {MdCheckboxModule} from '@angular2-material/checkbox/checkbox';
@@ -52,8 +52,45 @@ const MATERIAL_MODULES = [
5252
];
5353

5454
@NgModule({
55-
imports: MATERIAL_MODULES,
55+
imports: [
56+
MdButtonModule,
57+
MdCardModule,
58+
MdCheckboxModule,
59+
MdGridListModule,
60+
MdInputModule,
61+
MdListModule,
62+
MdProgressBarModule,
63+
MdProgressCircleModule,
64+
MdRippleModule,
65+
MdSidenavModule,
66+
MdSliderModule,
67+
MdSlideToggleModule,
68+
MdTabsModule,
69+
MdToolbarModule,
70+
PortalModule,
71+
RtlModule,
72+
73+
// These modules include providers.
74+
MdButtonToggleModule.forRoot(),
75+
MdDialogModule.forRoot(),
76+
MdIconModule.forRoot(),
77+
MdMenuModule.forRoot(),
78+
MdRadioModule.forRoot(),
79+
MdTooltipModule.forRoot(),
80+
OverlayModule.forRoot(),
81+
],
5682
exports: MATERIAL_MODULES,
5783
providers: [MdLiveAnnouncer]
5884
})
59-
export class MaterialModule { }
85+
export class MaterialRootModule { }
86+
87+
88+
@NgModule({
89+
imports: MATERIAL_MODULES,
90+
exports: MATERIAL_MODULES,
91+
})
92+
export class MaterialModule {
93+
static forRoot(): ModuleWithProviders {
94+
return {ngModule: MaterialRootModule};
95+
}
96+
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe('MdButtonToggle', () => {
2020

2121
beforeEach(async(() => {
2222
TestBed.configureTestingModule({
23-
imports: [MdButtonToggleModule, FormsModule],
23+
imports: [MdButtonToggleModule.forRoot(), FormsModule],
2424
declarations: [
2525
ButtonTogglesInsideButtonToggleGroup,
2626
ButtonToggleGroupWithNgModel,

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

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {
22
NgModule,
3+
ModuleWithProviders,
34
Component,
45
ContentChildren,
56
Directive,
@@ -385,18 +386,17 @@ export class MdButtonToggle implements OnInit {
385386
}
386387
}
387388

388-
/** @deprecated */
389-
export const MD_BUTTON_TOGGLE_DIRECTIVES = [
390-
MdButtonToggleGroup,
391-
MdButtonToggleGroupMultiple,
392-
MdButtonToggle
393-
];
394-
395389

396390
@NgModule({
397391
imports: [FormsModule],
398-
exports: MD_BUTTON_TOGGLE_DIRECTIVES,
399-
declarations: MD_BUTTON_TOGGLE_DIRECTIVES,
400-
providers: [MdUniqueSelectionDispatcher],
392+
exports: [MdButtonToggleGroup, MdButtonToggleGroupMultiple, MdButtonToggle],
393+
declarations: [MdButtonToggleGroup, MdButtonToggleGroupMultiple, MdButtonToggle],
401394
})
402-
export class MdButtonToggleModule { }
395+
export class MdButtonToggleModule {
396+
static forRoot(): ModuleWithProviders {
397+
return {
398+
ngModule: MdButtonToggleModule,
399+
providers: [MdUniqueSelectionDispatcher]
400+
};
401+
}
402+
}

src/lib/button/button.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -156,13 +156,9 @@ export class MdAnchor extends MdButton {
156156
}
157157

158158

159-
/** @deprecated */
160-
export const MD_BUTTON_DIRECTIVES: any[] = [MdButton, MdAnchor];
161-
162-
163159
@NgModule({
164160
imports: [CommonModule, MdRippleModule],
165-
exports: MD_BUTTON_DIRECTIVES,
166-
declarations: MD_BUTTON_DIRECTIVES,
161+
exports: [MdButton, MdAnchor],
162+
declarations: [MdButton, MdAnchor],
167163
})
168164
export class MdButtonModule { }

src/lib/card/card.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,15 @@ TODO(kara): update link to demo site when it exists
113113
})
114114
export class MdCardTitleGroup {}
115115

116-
/** @deprecated */
117-
export const MD_CARD_DIRECTIVES: any[] = [
118-
MdCard, MdCardContent, MdCardHeader, MdCardTitleGroup, MdCardTitle, MdCardSubtitle,
119-
MdCardActions
120-
];
121-
122116

123117
@NgModule({
124-
exports: MD_CARD_DIRECTIVES,
125-
declarations: MD_CARD_DIRECTIVES,
118+
exports: [
119+
MdCard, MdCardHeader, MdCardTitleGroup, MdCardContent, MdCardTitle, MdCardSubtitle,
120+
MdCardActions
121+
],
122+
declarations: [
123+
MdCard, MdCardHeader, MdCardTitleGroup, MdCardContent, MdCardTitle, MdCardSubtitle,
124+
MdCardActions
125+
],
126126
})
127127
export class MdCardModule { }

src/lib/checkbox/checkbox.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -304,12 +304,9 @@ export class MdCheckbox implements ControlValueAccessor {
304304
}
305305
}
306306

307-
/** @deprecated */
308-
export const MD_CHECKBOX_DIRECTIVES = [MdCheckbox];
309-
310307

311308
@NgModule({
312-
exports: MD_CHECKBOX_DIRECTIVES,
313-
declarations: MD_CHECKBOX_DIRECTIVES,
309+
exports: [MdCheckbox],
310+
declarations: [MdCheckbox],
314311
})
315312
export class MdCheckboxModule { }

src/lib/core/core.ts

+12-16
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {NgModule} from '@angular/core';
1+
import {NgModule, ModuleWithProviders} from '@angular/core';
22
import {MdLineModule} from './line/line';
33
import {RtlModule} from './rtl/dir';
44
import {MdRippleModule} from './ripple/ripple';
@@ -20,7 +20,6 @@ export {
2020
export {
2121
PortalHostDirective,
2222
TemplatePortalDirective,
23-
PORTAL_DIRECTIVES,
2423
PortalModule,
2524
} from './portal/portal-directives';
2625
export {DomPortalHost} from './portal/dom-portal-host';
@@ -33,7 +32,6 @@ export {OverlayState} from './overlay/overlay-state';
3332
export {
3433
ConnectedOverlayDirective,
3534
OverlayOrigin,
36-
OVERLAY_DIRECTIVES,
3735
OverlayModule,
3836
} from './overlay/overlay-directives';
3937
export {
@@ -45,7 +43,7 @@ export {
4543
export {MdGestureConfig} from './gestures/MdGestureConfig';
4644

4745
// Ripple
48-
export {MD_RIPPLE_DIRECTIVES, MdRipple, MdRippleModule} from './ripple/ripple';
46+
export {MdRipple, MdRippleModule} from './ripple/ripple';
4947

5048
// a11y
5149
export {
@@ -62,17 +60,15 @@ export {
6260
export {MdLineModule, MdLine, MdLineSetter} from './line/line';
6361

6462

65-
const coreModules = [
66-
MdLineModule,
67-
RtlModule,
68-
MdRippleModule,
69-
PortalModule,
70-
OverlayModule,
71-
];
72-
7363
@NgModule({
74-
imports: coreModules,
75-
exports: coreModules,
76-
providers: [MdLiveAnnouncer],
64+
imports: [MdLineModule, RtlModule, MdRippleModule, PortalModule, OverlayModule],
65+
exports: [MdLineModule, RtlModule, MdRippleModule, PortalModule, OverlayModule],
7766
})
78-
export class MdCoreModule { }
67+
export class MdCoreModule {
68+
static forRoot(): ModuleWithProviders {
69+
return {
70+
ngModule: MdCoreModule,
71+
providers: [MdLiveAnnouncer]
72+
};
73+
}
74+
}

src/lib/core/overlay/overlay-directives.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ describe('Overlay directives', () => {
1111

1212
beforeEach(async(() => {
1313
TestBed.configureTestingModule({
14-
imports: [OverlayModule],
14+
imports: [OverlayModule.forRoot()],
1515
declarations: [ConnectedOverlayDirectiveTest],
1616
providers: [
1717
{provide: OverlayContainer, useFactory: () => {

src/lib/core/overlay/overlay-directives.ts

+12-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {
22
NgModule,
3+
ModuleWithProviders,
34
Directive,
45
TemplateRef,
56
ViewContainerRef,
@@ -15,6 +16,7 @@ import {OverlayState} from './overlay-state';
1516
import {ConnectionPositionPair} from './position/connected-position';
1617
import {PortalModule} from '../portal/portal-directives';
1718

19+
1820
/** Default set of positions for the overlay. Follows the behavior of a dropdown. */
1921
let defaultPositionList = [
2022
new ConnectionPositionPair(
@@ -104,13 +106,16 @@ export class ConnectedOverlayDirective implements OnInit, OnDestroy {
104106
}
105107

106108

107-
export const OVERLAY_DIRECTIVES = [ConnectedOverlayDirective, OverlayOrigin];
108-
109-
110109
@NgModule({
111110
imports: [PortalModule],
112-
exports: OVERLAY_DIRECTIVES,
113-
declarations: OVERLAY_DIRECTIVES,
114-
providers: OVERLAY_PROVIDERS,
111+
exports: [ConnectedOverlayDirective, OverlayOrigin],
112+
declarations: [ConnectedOverlayDirective, OverlayOrigin],
115113
})
116-
export class OverlayModule { }
114+
export class OverlayModule {
115+
static forRoot(): ModuleWithProviders {
116+
return {
117+
ngModule: OverlayModule,
118+
providers: OVERLAY_PROVIDERS,
119+
};
120+
}
121+
}

src/lib/core/overlay/overlay.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ describe('Overlay', () => {
1717

1818
beforeEach(async(() => {
1919
TestBed.configureTestingModule({
20-
imports: [OverlayModule, PortalModule, OverlayTestModule],
20+
imports: [OverlayModule.forRoot(), PortalModule, OverlayTestModule],
2121
providers: [
2222
{provide: OverlayContainer, useFactory: () => {
2323
overlayContainerElement = document.createElement('div');

src/lib/core/overlay/overlay.ts

-2
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,10 @@ export class Overlay {
8282
}
8383
}
8484

85-
8685
/** Providers for Overlay and its related injectables. */
8786
export const OVERLAY_PROVIDERS = [
8887
ViewportRuler,
8988
OverlayPositionBuilder,
9089
Overlay,
9190
OverlayContainer,
9291
];
93-

src/lib/core/portal/portal-directives.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,9 @@ export class PortalHostDirective extends BasePortalHost {
102102
}
103103
}
104104

105-
export const PORTAL_DIRECTIVES = [TemplatePortalDirective, PortalHostDirective];
106-
107105

108106
@NgModule({
109-
exports: PORTAL_DIRECTIVES,
110-
declarations: PORTAL_DIRECTIVES,
107+
exports: [TemplatePortalDirective, PortalHostDirective],
108+
declarations: [TemplatePortalDirective, PortalHostDirective],
111109
})
112110
export class PortalModule { }

src/lib/core/ripple/ripple.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,9 @@ export class MdRipple implements OnInit, OnDestroy, OnChanges {
168168
// TODO: Reactivate the background div if the user drags out and back in.
169169
}
170170

171-
/** @deprecated */
172-
export const MD_RIPPLE_DIRECTIVES = [MdRipple];
173-
174171

175172
@NgModule({
176-
exports: MD_RIPPLE_DIRECTIVES,
177-
declarations: MD_RIPPLE_DIRECTIVES,
173+
exports: [MdRipple],
174+
declarations: [MdRipple],
178175
})
179176
export class MdRippleModule { }

src/lib/dialog/dialog.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ describe('MdDialog', () => {
1515

1616
beforeEach(async(() => {
1717
TestBed.configureTestingModule({
18-
imports: [MdDialogModule, DialogTestModule],
18+
imports: [MdDialogModule.forRoot(), DialogTestModule],
1919
providers: [
2020
{provide: OverlayContainer, useFactory: () => {
2121
overlayContainerElement = document.createElement('div');

0 commit comments

Comments
 (0)