Skip to content

Commit 1cf4420

Browse files
author
vakrilov
committed
test(router): Added lazy module in e2e proj
1 parent 78e6625 commit 1cf4420

File tree

5 files changed

+77
-2
lines changed

5 files changed

+77
-2
lines changed

e2e/router/app/app-routing.module.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ export const routes = [
2323
{ path: "detail/:id", component: DetailComponent }
2424
]
2525
},
26+
{
27+
path: "lazy",
28+
loadChildren: "./lazy/lazy.module#LazyModule",
29+
}
2630
];
2731

2832
export const navigatableComponents = [

e2e/router/app/app.module.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { NgModule, NO_ERRORS_SCHEMA } from "@angular/core";
1+
import { NgModule, NgModuleFactoryLoader, NO_ERRORS_SCHEMA } from "@angular/core";
22
import { NativeScriptModule } from "nativescript-angular/nativescript.module";
3+
import { NSModuleFactoryLoader } from "nativescript-angular/router";
34

45
import "./rxjs-operators";
56

@@ -21,7 +22,9 @@ enable();
2122
...navigatableComponents,
2223
],
2324
bootstrap: [AppComponent],
24-
providers: [],
25+
providers: [
26+
{ provide: NgModuleFactoryLoader, useClass: NSModuleFactoryLoader }
27+
],
2528
imports: [
2629
NativeScriptModule,
2730
AppRoutingModule,

e2e/router/app/first/first.component.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import { Observable } from "rxjs/Observable";
1313
<Label text="FirstComponent" class="header"></Label>
1414
1515
<Button text="GO TO SECOND" [nsRouterLink]="['/second','1']"></Button>
16+
<Button text="GO TO LAZY" [nsRouterLink]="['/lazy','home']"></Button>
17+
1618
<Button text="BACK" (tap)="goBack()"></Button>
1719
<Label [text]="message"></Label>
1820
</StackLayout>`

e2e/router/app/lazy/lazy.component.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { Component, OnInit, OnDestroy, OnChanges } from "@angular/core";
2+
import { ActivatedRoute, Router, Route } from "@angular/router";
3+
import { Location } from "@angular/common";
4+
import { RouterExtensions } from "nativescript-angular/router";
5+
6+
import { Page } from "ui/page";
7+
import { Observable } from "rxjs/Observable";
8+
9+
@Component({
10+
selector: "lazy",
11+
template: `
12+
<StackLayout>
13+
<Label text="LazyComponent" class="header"></Label>
14+
15+
<Button text="GO TO FIRST" [nsRouterLink]="['/first']"></Button>
16+
<Button text="BACK" (tap)="goBack()"></Button>
17+
<Label [text]="message"></Label>
18+
</StackLayout>`
19+
})
20+
export class LazyComponent implements OnInit, OnDestroy {
21+
public message: string = "";
22+
constructor(private routerExt: RouterExtensions, page: Page) {
23+
console.log("LazyComponent - constructor() page: " + page);
24+
}
25+
26+
ngOnInit() {
27+
console.log("LazyComponent - ngOnInit()");
28+
}
29+
30+
ngOnDestroy() {
31+
console.log("LazyComponent - ngOnDestroy()");
32+
}
33+
34+
goBack() {
35+
this.message = "";
36+
if (this.routerExt.canGoBack()) {
37+
this.routerExt.back();
38+
} else {
39+
this.message = "canGoBack() - false"
40+
}
41+
}
42+
}

e2e/router/app/lazy/lazy.module.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { NgModule, NO_ERRORS_SCHEMA } from "@angular/core";
2+
import { NativeScriptModule } from "nativescript-angular/nativescript.module";
3+
import { NativeScriptRouterModule } from "nativescript-angular/router";
4+
5+
import { LazyComponent } from "./lazy.component";
6+
7+
8+
const routes = [
9+
{
10+
path: "home",
11+
component: LazyComponent
12+
}
13+
];
14+
15+
@NgModule({
16+
schemas: [NO_ERRORS_SCHEMA],
17+
imports: [
18+
NativeScriptModule,
19+
NativeScriptRouterModule,
20+
NativeScriptRouterModule.forChild(routes)
21+
],
22+
declarations: [LazyComponent]
23+
})
24+
export class LazyModule { }

0 commit comments

Comments
 (0)