Skip to content
This repository was archived by the owner on Jan 6, 2025. It is now read-only.

Commit 85e3145

Browse files
CaerusKaruThomasBurleson
authored andcommitted
fix(module): make withConfig AOT compatible
1 parent 28bc2ae commit 85e3145

File tree

3 files changed

+21
-26
lines changed

3 files changed

+21
-26
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const PRINT_BREAKPOINTS = [{
2323
BrowserAnimationsModule,
2424
RoutingModule,
2525
DemoMaterialModule,
26-
FlexLayoutModule,
26+
FlexLayoutModule.withConfig({useColumnBasisZero: false}),
2727
],
2828
providers: [{provide: BREAKPOINT, useValue: PRINT_BREAKPOINTS, multi: true}],
2929
bootstrap: [AppComponent]

src/lib/flex/flex/flex.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,9 @@ export class FlexDirective extends BaseDirective implements OnInit, OnChanges, O
163163
protected _validateValue(grow: number|string,
164164
shrink: number|string,
165165
basis: string|number|FlexBasisAlias) {
166+
let addFlexToParent = this.layoutConfig.addFlexToParent !== false;
166167
// The flex-direction of this element's flex container. Defaults to 'row'.
167-
let layout = this._getFlexFlowDirection(this.parentElement, this.layoutConfig.addFlexToParent);
168+
let layout = this._getFlexFlowDirection(this.parentElement, addFlexToParent);
168169
let direction = (layout.indexOf('column') > -1) ? 'column' : 'row';
169170

170171
let max = isFlowHorizontal(direction) ? 'max-width' : 'max-height';

src/lib/module.ts

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,10 @@ import {
1111
NgModule,
1212
Optional,
1313
PLATFORM_ID,
14-
Provider,
1514
} from '@angular/core';
1615
import {isPlatformServer} from '@angular/common';
1716
import {
1817
SERVER_TOKEN,
19-
DEFAULT_CONFIG,
2018
LayoutConfigOptions,
2119
LAYOUT_CONFIG,
2220
BreakPoint,
@@ -50,30 +48,26 @@ export class FlexLayoutModule {
5048
*/
5149
static withConfig(configOptions: LayoutConfigOptions,
5250
breakpoints?: BreakPoint|BreakPoint[]): ModuleWithProviders {
53-
const config = Object.assign({}, DEFAULT_CONFIG);
54-
const moduleProviders: Provider[] = [];
55-
56-
for (const key in configOptions) {
57-
// If the setting is different and not undefined or null, change it
58-
if (configOptions[key] !== config[key] &&
59-
(configOptions[key] === false || configOptions[key] === true)) {
60-
config[key] = configOptions[key];
61-
}
62-
}
63-
64-
if (configOptions.serverLoaded) {
65-
moduleProviders.push({provide: SERVER_TOKEN, useValue: true});
66-
}
67-
68-
if (Array.isArray(breakpoints)) {
69-
moduleProviders.push({provide: BREAKPOINT, useValue: breakpoints, multi: true});
70-
}
71-
72-
moduleProviders.push({provide: LAYOUT_CONFIG, useValue: config});
73-
7451
return {
7552
ngModule: FlexLayoutModule,
76-
providers: moduleProviders
53+
providers: Array.isArray(breakpoints) ?
54+
configOptions.serverLoaded ?
55+
[
56+
{provide: LAYOUT_CONFIG, useValue: configOptions},
57+
{provide: BREAKPOINT, useValue: breakpoints, multi: true},
58+
{provide: SERVER_TOKEN, useValue: true},
59+
] : [
60+
{provide: LAYOUT_CONFIG, useValue: configOptions},
61+
{provide: BREAKPOINT, useValue: breakpoints, multi: true},
62+
]
63+
:
64+
configOptions.serverLoaded ?
65+
[
66+
{provide: LAYOUT_CONFIG, useValue: configOptions},
67+
] :
68+
[
69+
{provide: LAYOUT_CONFIG, useValue: configOptions},
70+
]
7771
};
7872
}
7973

0 commit comments

Comments
 (0)