Skip to content

Commit a735506

Browse files
committed
Fix PageRouterOutlet for rc5. Get first example running.
1 parent e20fe8c commit a735506

File tree

3 files changed

+49
-43
lines changed

3 files changed

+49
-43
lines changed

nativescript-angular/router/page-router-outlet.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import {
22
Attribute, ComponentFactory, ComponentRef, Directive,
33
ReflectiveInjector, ResolvedReflectiveProvider, ViewContainerRef,
44
Inject, ComponentResolver, provide, ComponentFactoryResolver,
5-
NoComponentFactoryError} from '@angular/core';
5+
NoComponentFactoryError, Injector
6+
} from '@angular/core';
67

78
import {isPresent} from '@angular/core/src/facade/lang';
89

@@ -103,7 +104,7 @@ export class PageRouterOutlet {
103104

104105
this.viewUtil = new ViewUtil(device);
105106
compiler.resolveComponent(DetachedLoader).then((detachedLoaderFactory) => {
106-
log("DetachedLoaderFactory leaded");
107+
log("DetachedLoaderFactory loaded");
107108
this.detachedLoaderFactory = detachedLoaderFactory;
108109
});
109110
}
@@ -145,11 +146,10 @@ export class PageRouterOutlet {
145146
* Called by the Router to instantiate a new component during the commit phase of a navigation.
146147
* This method in turn is responsible for calling the `routerOnActivate` hook of its child.
147148
*/
148-
activate(
149-
activatedRoute: ActivatedRoute,
150-
providers: ResolvedReflectiveProvider[],
151-
outletMap: RouterOutletMap): void {
152-
149+
activate(
150+
activatedRoute: ActivatedRoute, loadedResolver: ComponentFactoryResolver,
151+
loadedInjector: Injector, providers: ResolvedReflectiveProvider[],
152+
outletMap: RouterOutletMap): void {
153153
this.outletMap = outletMap;
154154
this.currentActivatedRoute = activatedRoute;
155155

@@ -272,4 +272,4 @@ export class PageRouterOutlet {
272272

273273
function log(msg: string) {
274274
routerLog(msg);
275-
}
275+
}

ng-sample/app/app.ts

+29-25
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import {LivesyncApp, LivesyncTestRouterProviders} from "./examples/livesync-test
3636

3737
// new router
3838
import { RouterOutletAppComponent } from "./examples/router/router-outlet-test";
39-
import { PageRouterOutletAppComponent, PageRouterOutletRouterProviders } from "./examples/router/page-router-outlet-test";
39+
import { PageRouterOutletAppComponent } from "./examples/router/page-router-outlet-test";
4040
import { PageRouterOutletNestedAppComponent, PageRouterOutletNestedRouterProviders } from "./examples/router/page-router-outlet-nested-test";
4141
import { ClearHistoryAppComponent, ClearHistoryRouterProviders } from "./examples/router/clear-history-test";
4242
import { LoginAppComponent, LoginExampleProviders } from "./examples/router/login-test";
@@ -47,12 +47,6 @@ import { AnimationKeyframesTest } from "./examples/animation/animation-keyframes
4747
import { AnimationNgClassTest } from "./examples/animation/animation-ngclass-test";
4848
import { AnimationStatesTest } from "./examples/animation/animation-states-test";
4949

50-
// nativeScriptBootstrap(RendererTest);
51-
//nativeScriptBootstrap(TabViewTest);
52-
//nativeScriptBootstrap(Benchmark);
53-
// nativeScriptBootstrap(ListTest);
54-
// nativeScriptBootstrap(ListTestAsync);
55-
//nativeScriptBootstrap(ImageTest);
5650
// nativeScriptBootstrap(HttpTest);
5751
//nativeScriptBootstrap(ActionBarTest, [NS_ROUTER_PROVIDERS_DEPRECATED], { startPageActionBarHidden: false });
5852
//nativeScriptBootstrap(ActionBarTest, [NS_ROUTER_PROVIDERS_DEPRECATED]);
@@ -83,24 +77,34 @@ import { AnimationStatesTest } from "./examples/animation/animation-states-test"
8377
})
8478
class ExampleModule {}
8579

86-
@NgModule({bootstrap: [RendererTest], declarations: [RendererTest], imports: [ExampleModule]})
87-
class RendererTestModule {}
88-
89-
@NgModule({bootstrap: [PageRouterOutletAppComponent], imports: [ExampleModule]})
90-
class PageRouterOutletAppModule {}
91-
92-
@NgModule({
93-
bootstrap: [RouterOutletAppComponent],
94-
imports: [
95-
ExampleModule,
96-
NativeScriptRouterModule.forRoot(RouterOutletAppComponent.routes),
97-
],
98-
})
99-
class RouterOutletAppModule {}
100-
101-
//platformNativeScriptDynamic().bootstrapModule(RendererTestModule);
102-
platformNativeScriptDynamic().bootstrapModule(RouterOutletAppModule);
103-
//platformNativeScriptDynamic().bootstrapModule(PageRouterOutletAppModule);
80+
function makeExampleModule(componentType, routes = null, entryComponents = null) {
81+
let imports: any[] = [ExampleModule];
82+
if (routes) {
83+
imports.push(NativeScriptRouterModule.forRoot(routes))
84+
}
85+
let entries = [];
86+
if (entryComponents) {
87+
entries = entryComponents;
88+
}
89+
@NgModule({
90+
bootstrap: [componentType],
91+
imports: imports,
92+
entryComponents: entries,
93+
declarations: entries,
94+
})
95+
class ExampleModuleForComponent {}
96+
97+
return ExampleModuleForComponent;
98+
}
99+
100+
//platformNativeScriptDynamic().bootstrapModule(makeExampleModule(RendererTest));
101+
//platformNativeScriptDynamic().bootstrapModule(makeExampleModule(TabViewTest));
102+
//platformNativeScriptDynamic().bootstrapModule(makeExampleModule(Benchmark));
103+
//platformNativeScriptDynamic().bootstrapModule(makeExampleModule(ListTest));
104+
//platformNativeScriptDynamic().bootstrapModule(makeExampleModule(ListTestAsync));
105+
//platformNativeScriptDynamic().bootstrapModule(makeExampleModule(ImageTest));
106+
//platformNativeScriptDynamic().bootstrapModule(makeExampleModule(RouterOutletAppComponent, RouterOutletAppComponent.routes));
107+
platformNativeScriptDynamic().bootstrapModule(makeExampleModule(PageRouterOutletAppComponent, PageRouterOutletAppComponent.routes, PageRouterOutletAppComponent.entries));
104108

105109
// Livesync test
106110
// var cahcedUrl: string;

ng-sample/app/examples/router/page-router-outlet-test.ts

+12-10
Original file line numberDiff line numberDiff line change
@@ -110,19 +110,21 @@ class ThirdComponent implements OnInit, OnDestroy {
110110
template: `<page-router-outlet></page-router-outlet>`
111111
})
112112
export class PageRouterOutletAppComponent {
113+
static routes: RouterConfig = [
114+
{ path: "", component: FirstComponent },
115+
{ path: "second/:id", component: SecondComponent },
116+
{ path: "third/:id", component: ThirdComponent },
117+
];
118+
119+
static entries = [
120+
FirstComponent,
121+
SecondComponent,
122+
ThirdComponent
123+
]
124+
113125
constructor(router: Router, private location: Location) {
114126
router.events.subscribe((e) => {
115127
console.log("--EVENT-->: " + e.toString());
116128
});
117129
}
118130
}
119-
120-
const routes: RouterConfig = [
121-
{ path: "", component: FirstComponent },
122-
{ path: "second/:id", component: SecondComponent },
123-
{ path: "third/:id", component: ThirdComponent },
124-
];
125-
126-
export const PageRouterOutletRouterProviders = [
127-
nsProvideRouter(routes, { enableTracing: false })
128-
];

0 commit comments

Comments
 (0)