Skip to content

Commit afdaec7

Browse files
feat(module): add additional configuration using forRoot and forFeature
1 parent 8382ac8 commit afdaec7

23 files changed

+315
-34
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { AppRoutingModule } from './app-routing.module';
1313
import { AppComponent } from './app.component';
1414
import { ServiceWorkerModule } from '@angular/service-worker';
1515
import { environment } from '../environments/environment';
16+
import { RootErrorComponent } from './shared/root-error/root-error.component';
1617

1718
@NgModule({
1819
schemas: [CUSTOM_ELEMENTS_SCHEMA],
@@ -25,7 +26,11 @@ import { environment } from '../environments/environment';
2526
ServiceWorkerModule.register('ngsw-worker.js', {
2627
enabled: environment.production
2728
}),
28-
LazyElementsModule,
29+
LazyElementsModule.forRoot({
30+
rootOptions: {
31+
errorComponent: RootErrorComponent
32+
}
33+
}),
2934

3035
// local
3136
CoreModule,

projects/elements-demo/src/app/features/examples/advanced/advanced.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ <h2>Elements configured in module with HTML inline options</h2>
5151
</p>
5252
<pre [highlight]="codeExample2html"></pre>
5353
<pre [highlight]="codeExample2module"></pre>
54+
<pre [highlight]="codeExample2coreModule"></pre>
5455
</div>
5556
</div>
5657

projects/elements-demo/src/app/features/examples/advanced/advanced.component.ts

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export class AdvancedComponent implements OnInit {
1515
codeExample1module = CODE_EXAMPLE_1_MODULE;
1616
codeExample1html = CODE_EXAMPLE_1_HTML;
1717
codeExample2module = CODE_EXAMPLE_2_MODULE;
18+
codeExample2coreModule = CODE_EXAMPLE_2_CORE_MODULE;
1819
codeExample2html = CODE_EXAMPLE_2_HTML;
1920
codeExample3module = CODE_EXAMPLE_3_MODULE;
2021
codeExample3html = CODE_EXAMPLE_3_HTML;
@@ -34,7 +35,12 @@ export class AdvancedComponent implements OnInit {
3435
const CODE_EXAMPLE_1_MODULE = `// pre-configured LazyElementsModule
3536
const options: LazyElementModuleOptions = {
3637
elementConfigs: [
37-
{ tag: 'ion-button', url: 'https://unpkg.com/@ionic/core@4.6.2/dist/ionic/ionic.js' }
38+
{
39+
tag: 'ion-button',
40+
url: 'https://unpkg.com/@ionic/core@4.6.2/dist/ionic/ionic.js',
41+
loadingComponent: SpinnerComponent,
42+
errorComponent: ErrorComponent
43+
}
3844
]
3945
};
4046
@@ -51,10 +57,13 @@ export class FeatureModule { }
5157
const CODE_EXAMPLE_1_HTML = `<!-- No need to specify url -->
5258
<ion-button *axLazyElement></ion-button>`;
5359

54-
const CODE_EXAMPLE_2_MODULE = `// pre-configured LazyElementsModule
60+
const CODE_EXAMPLE_2_MODULE = `// pre-configured LazyElementsModule in FeatureModule
5561
const options: LazyElementModuleOptions = {
5662
elementConfigs: [
57-
{ tag: 'mwc-checkbox', url: 'https://unpkg.com/@material/mwc-checkbox@0.6.0/mwc-checkbox.js?module' }
63+
{
64+
tag: 'mwc-checkbox',
65+
url: 'https://unpkg.com/@material/mwc-checkbox@0.6.0/mwc-checkbox.js?module'
66+
}
5867
]
5968
};
6069
@@ -68,6 +77,22 @@ const options: LazyElementModuleOptions = {
6877
export class FeatureModule { }
6978
`;
7079

80+
const CODE_EXAMPLE_2_CORE_MODULE = `// pre-configured LazyElementsModule in CoreModule or AppModule
81+
const options: LazyElementModuleRootOptions = {
82+
rootOptions: {
83+
errorComponent: RootErrorComponent
84+
}
85+
};
86+
87+
@NgModule({
88+
schemas: [CUSTOM_ELEMENTS_SCHEMA],
89+
imports: [
90+
LazyElementsModule.forRoot(options),
91+
]
92+
})
93+
export class CoreModule { }
94+
`;
95+
7196
const CODE_EXAMPLE_2_HTML = `<!-- We have to specify null; url to be able to pass in additional options -->
7297
<mwc-checkbox *axLazyElement="null; module: true; loadingTemplate: loading;"></mwc-checkbox>`;
7398

projects/elements-demo/src/app/features/examples/advanced/advanced.module.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,16 @@ import { SharedModule } from '../../../shared/shared.module';
1010

1111
import { AdvancedRoutingModule } from './advanced-routing.module';
1212
import { AdvancedComponent } from './advanced.component';
13+
import { SpinnerComponent } from '../../../shared/spinner/spinner.component';
14+
import { ErrorComponent } from '../../../shared/error/error.component';
1315

1416
const options: LazyElementModuleOptions = {
1517
elementConfigs: [
1618
{
1719
tag: 'ion-button',
18-
url: 'https://unpkg.com/@ionic/core@4.6.2/dist/ionic/ionic.js'
20+
url: 'https://unpkg.com/@ionic/core@4.6.2/dist/ionic/ionic.js',
21+
loadingComponent: SpinnerComponent,
22+
errorComponent: ErrorComponent
1923
},
2024
{
2125
tag: 'mwc-switch',
@@ -25,7 +29,8 @@ const options: LazyElementModuleOptions = {
2529
{
2630
tag: 'mwc-checkbox',
2731
url:
28-
'https://unpkg.com/@material/mwc-checkbox@0.6.0/mwc-checkbox.js?module'
32+
'https://unpkg.com/@material/mwc-checkbox@0.6.0/mwc-checkbox.js?module',
33+
isModule: true
2934
}
3035
]
3136
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<p>Loading failed ⚠️...</p>

projects/elements-demo/src/app/shared/error/error.component.scss

Whitespace-only changes.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2+
3+
import { ErrorComponent } from './error.component';
4+
5+
describe('ErrorComponent', () => {
6+
let component: ErrorComponent;
7+
let fixture: ComponentFixture<ErrorComponent>;
8+
9+
beforeEach(async(() => {
10+
TestBed.configureTestingModule({
11+
declarations: [ErrorComponent]
12+
}).compileComponents();
13+
}));
14+
15+
beforeEach(() => {
16+
fixture = TestBed.createComponent(ErrorComponent);
17+
component = fixture.componentInstance;
18+
fixture.detectChanges();
19+
});
20+
21+
it('should create', () => {
22+
expect(component).toBeTruthy();
23+
});
24+
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { Component, OnInit } from '@angular/core';
2+
3+
@Component({
4+
selector: 'demo-error',
5+
templateUrl: './error.component.html',
6+
styleUrls: ['./error.component.scss']
7+
})
8+
export class ErrorComponent implements OnInit {
9+
constructor() {}
10+
11+
ngOnInit() {}
12+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<p>root loading error...</p>

projects/elements-demo/src/app/shared/root-error/root-error.component.scss

Whitespace-only changes.

0 commit comments

Comments
 (0)