Skip to content

Commit 8d832bc

Browse files
committed
fix(page-router-outlet): activateWith instead of activate method
caused by: angular/angular#15044
1 parent a6d9247 commit 8d832bc

File tree

1 file changed

+34
-22
lines changed

1 file changed

+34
-22
lines changed

Diff for: nativescript-angular/router/page-router-outlet.ts

+34-22
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {
22
Attribute, ComponentFactory, ComponentRef, Directive,
3-
ReflectiveInjector, ResolvedReflectiveProvider, ViewContainerRef,
3+
ViewContainerRef,
44
Inject, ComponentFactoryResolver, Injector
55
} from "@angular/core";
66
import { isPresent } from "../lang-facade";
@@ -68,7 +68,9 @@ export class PageRouterOutlet { // tslint:disable-line:directive-class-suffix
6868

6969
public outletMap: RouterOutletMap;
7070

71-
get locationInjector(): Injector { return this.containerRef.injector; }
71+
/** @deprecated from Angular since v4 */
72+
get locationInjector(): Injector { return this.location.injector; }
73+
/** @deprecated from Angular since v4 */
7274
get locationFactoryResolver(): ComponentFactoryResolver { return this.resolver; }
7375

7476
get isActivated(): boolean {
@@ -92,7 +94,7 @@ export class PageRouterOutlet { // tslint:disable-line:directive-class-suffix
9294

9395
constructor(
9496
parentOutletMap: RouterOutletMap,
95-
private containerRef: ViewContainerRef,
97+
private location: ViewContainerRef,
9698
@Attribute("name") name: string,
9799
private locationStrategy: NSLocationStrategy,
98100
private componentFactoryResolver: ComponentFactoryResolver,
@@ -145,37 +147,35 @@ export class PageRouterOutlet { // tslint:disable-line:directive-class-suffix
145147
* Called by the Router to instantiate a new component during the commit phase of a navigation.
146148
* This method in turn is responsible for calling the `routerOnActivate` hook of its child.
147149
*/
148-
activate(
149-
activatedRoute: ActivatedRoute, resolver: ComponentFactoryResolver, injector: Injector,
150-
providers: ResolvedReflectiveProvider[], outletMap: RouterOutletMap): void {
150+
activateWith(
151+
activatedRoute: ActivatedRoute, resolver: ComponentFactoryResolver|null,
152+
outletMap: RouterOutletMap): void {
151153
this.outletMap = outletMap;
152154
this.currentActivatedRoute = activatedRoute;
153155

156+
resolver = resolver || this.resolver;
157+
154158
if (this.locationStrategy._isPageNavigatingBack()) {
155159
this.activateOnGoBack(activatedRoute, outletMap);
156160
} else {
157-
this.activateOnGoForward(activatedRoute, providers, outletMap, resolver, injector);
161+
this.activateOnGoForward(activatedRoute, outletMap, resolver);
158162
}
159163
}
160164

161165
private activateOnGoForward(
162166
activatedRoute: ActivatedRoute,
163-
providers: ResolvedReflectiveProvider[],
164167
outletMap: RouterOutletMap,
165-
loadedResolver: ComponentFactoryResolver,
166-
injector: Injector): void {
168+
loadedResolver: ComponentFactoryResolver): void {
167169
const factory = this.getComponentFactory(activatedRoute, loadedResolver);
168170

169171
const pageRoute = new PageRoute(activatedRoute);
170-
providers = [...providers, ...ReflectiveInjector.resolve(
171-
[{ provide: PageRoute, useValue: pageRoute }])];
172+
const inj = new OutletInjector(activatedRoute, outletMap, this.location.injector);
172173

173174
if (this.isInitialPage) {
174175
log("PageRouterOutlet.activate() initial page - just load component");
175176
this.isInitialPage = false;
176-
const inj = ReflectiveInjector.fromResolvedProviders(providers, injector);
177-
this.currentActivatedComp = this.containerRef.createComponent(
178-
factory, this.containerRef.length, inj, []);
177+
this.currentActivatedComp = this.location.createComponent(
178+
factory, this.location.length, inj, []);
179179

180180
this.currentActivatedComp.changeDetectorRef.detectChanges();
181181

@@ -189,13 +189,8 @@ export class PageRouterOutlet { // tslint:disable-line:directive-class-suffix
189189
isNavigation: true,
190190
componentType: factory.componentType
191191
});
192-
const pageResolvedProvider = ReflectiveInjector.resolve([
193-
{ provide: Page, useValue: page }
194-
]);
195-
const childInjector = ReflectiveInjector.fromResolvedProviders(
196-
[...providers, ...pageResolvedProvider], injector);
197-
const loaderRef = this.containerRef.createComponent(
198-
this.detachedLoaderFactory, this.containerRef.length, childInjector, []);
192+
const loaderRef = this.location.createComponent(
193+
this.detachedLoaderFactory, this.location.length, inj, []);
199194
loaderRef.changeDetectorRef.detectChanges();
200195

201196
this.currentActivatedComp = loaderRef.instance.loadWithFactory(factory);
@@ -275,6 +270,23 @@ export class PageRouterOutlet { // tslint:disable-line:directive-class-suffix
275270
}
276271
}
277272

273+
class OutletInjector implements Injector {
274+
constructor(
275+
private route: ActivatedRoute, private map: RouterOutletMap, private parent: Injector) { }
276+
277+
get(token: any, notFoundValue?: any): any {
278+
if (token === ActivatedRoute) {
279+
return this.route;
280+
}
281+
282+
if (token === RouterOutletMap) {
283+
return this.map;
284+
}
285+
286+
return this.parent.get(token, notFoundValue);
287+
}
288+
}
289+
278290
function log(msg: string) {
279291
routerLog(msg);
280292
}

0 commit comments

Comments
 (0)