Modifying angular bootstrap to add injection at the module level (#1691)

* work on fixing injection

* change bootstrapping method

* add a catch for testing

* remove unneeded code
This commit is contained in:
Anthony Dresser
2018-06-22 16:09:13 -07:00
committed by GitHub
parent a627285a4c
commit 473ddfcdf1
11 changed files with 127 additions and 152 deletions

View File

@@ -4,20 +4,23 @@
*--------------------------------------------------------------------------------------------*/
import {
ApplicationRef, ComponentFactoryResolver, ModuleWithProviders, NgModule,
ApplicationRef, ComponentFactoryResolver, NgModule,
Inject, forwardRef, Type
} from '@angular/core';
import { APP_BASE_HREF, CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { BrowserModule } from '@angular/platform-browser';
import { IBootstrapParams } from 'sql/services/bootstrap/bootstrapService';
import { BackupComponent, BACKUP_SELECTOR } from 'sql/parts/disasterRecovery/backup/backup.component';
import { IBootstrapParams, ISelector, providerIterator } from 'sql/services/bootstrap/bootstrapService';
import { BackupComponent } from 'sql/parts/disasterRecovery/backup/backup.component';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
// work around
const BrowserAnimationsModule = (<any>require.__$__nodeRequire('@angular/platform-browser/animations')).BrowserAnimationsModule;
// Backup wizard main angular module
export const BackupModule = (params: IBootstrapParams, selector: string): Type<any> => {
export const BackupModule = (params: IBootstrapParams, selector: string, instantiationService: IInstantiationService): Type<any> => {
@NgModule({
declarations: [
BackupComponent
@@ -31,19 +34,22 @@ export const BackupModule = (params: IBootstrapParams, selector: string): Type<a
],
providers: [
{ provide: APP_BASE_HREF, useValue: '/' },
{ provide: IBootstrapParams, useValue: params }
{ provide: IBootstrapParams, useValue: params },
{ provide: ISelector, useValue: selector },
...providerIterator(instantiationService)
]
})
class ModuleClass {
constructor(
@Inject(forwardRef(() => ComponentFactoryResolver)) private _resolver: ComponentFactoryResolver
@Inject(forwardRef(() => ComponentFactoryResolver)) private _resolver: ComponentFactoryResolver,
@Inject(ISelector) private selector: string
) {
}
ngDoBootstrap(appRef: ApplicationRef) {
const factory = this._resolver.resolveComponentFactory(BackupComponent);
(<any>factory).factory.selector = selector;
(<any>factory).factory.selector = this.selector;
appRef.bootstrap(factory);
}
}