refactor(router): use ApplicationRef to provide the first bootstrapped component as ROUTER_PRIMARY_COMPONENT automatically.
This removes the routerBindings function as it is no longer necessary. ROUTER_BINDINGS will automatically pick the first bootstrapped component to satisfy ROUTER_PRIMARY_COMPONENT. BREAKING CHANGE: Before: bootstrap(MyComponent, [routerBindings(myComponent)]); After: bootstrap(MyComponent, [ROUTER_BINDINGS]); Closes #4643
This commit is contained in:
@ -230,9 +230,10 @@ export class PlatformRef_ extends PlatformRef {
|
||||
|
||||
private _initApp(zone: NgZone, bindings: Array<Type | Binding | any[]>): ApplicationRef {
|
||||
var injector: Injector;
|
||||
var app: ApplicationRef;
|
||||
zone.run(() => {
|
||||
bindings.push(bind(NgZone).toValue(zone));
|
||||
bindings.push(bind(ApplicationRef).toValue(this));
|
||||
bindings.push(bind(ApplicationRef).toFactory((): ApplicationRef => app, []));
|
||||
|
||||
var exceptionHandler;
|
||||
try {
|
||||
@ -247,7 +248,7 @@ export class PlatformRef_ extends PlatformRef {
|
||||
}
|
||||
}
|
||||
});
|
||||
var app = new ApplicationRef_(this, zone, injector);
|
||||
app = new ApplicationRef_(this, zone, injector);
|
||||
this._applications.push(app);
|
||||
return app;
|
||||
}
|
||||
@ -312,11 +313,17 @@ export abstract class ApplicationRef {
|
||||
* Dispose of this application and all of its components.
|
||||
*/
|
||||
abstract dispose(): void;
|
||||
|
||||
/**
|
||||
* Get a list of component types registered to this application.
|
||||
*/
|
||||
get componentTypes(): Type[] { return unimplemented(); };
|
||||
}
|
||||
|
||||
export class ApplicationRef_ extends ApplicationRef {
|
||||
private _bootstrapListeners: Function[] = [];
|
||||
private _rootComponents: ComponentRef[] = [];
|
||||
private _rootComponentTypes: Type[] = [];
|
||||
|
||||
constructor(private _platform: PlatformRef_, private _zone: NgZone, private _injector: Injector) {
|
||||
super();
|
||||
@ -334,6 +341,7 @@ export class ApplicationRef_ extends ApplicationRef {
|
||||
componentBindings.push(bindings);
|
||||
}
|
||||
var exceptionHandler = this._injector.get(ExceptionHandler);
|
||||
this._rootComponentTypes.push(componentType);
|
||||
try {
|
||||
var injector: Injector = this._injector.resolveAndCreateChild(componentBindings);
|
||||
var compRefToken: Promise<ComponentRef> = injector.get(APP_COMPONENT_REF_PROMISE);
|
||||
@ -369,4 +377,6 @@ export class ApplicationRef_ extends ApplicationRef {
|
||||
this._rootComponents.forEach((ref) => ref.dispose());
|
||||
this._platform._applicationDisposed(this);
|
||||
}
|
||||
|
||||
get componentTypes(): any[] { return this._rootComponentTypes; }
|
||||
}
|
||||
|
Reference in New Issue
Block a user