feat(ngUpgrade): add support for NgModules

BREAKING CHANGE: UpgradeAdapter.addProvider are now deprecated in favor of passing in an NgModule into the adapter's constructor

Before:

```
let upgradeAdapter = new UpgradeAdapter();
upgradeAdapter.addProviders([myProvidersArray);
```

After:

```
@NgModule({
  providers: myProvidersArray
})
class MyModule {}

let upgradeAdapter = new UpgradeAdapter(MyModule);
```
This commit is contained in:
Igor Minar 2016-08-03 17:42:32 -07:00 committed by Misko Hevery
parent d4cceff0ef
commit 6b564ecda5
1 changed files with 8 additions and 1 deletions

View File

@ -100,6 +100,10 @@ export class UpgradeAdapter {
/* @internal */ /* @internal */
private providers: Array<Type|Provider|any[]|any> = []; private providers: Array<Type|Provider|any[]|any> = [];
// the ng2AppModule param should be required once the deprecated @Component.directives prop is
// removed
constructor(private ng2AppModule?: Type) {}
/** /**
* Allows Angular v2 Component to be used from AngularJS v1. * Allows Angular v2 Component to be used from AngularJS v1.
* *
@ -289,7 +293,7 @@ export class UpgradeAdapter {
ngDoBootstrap() {} ngDoBootstrap() {}
} }
platformRef.bootstrapModule(DynamicModule).then((moduleRef) => { platformRef.bootstrapModule(<any>this.ng2AppModule || DynamicModule).then((moduleRef) => {
ng1Injector = this._afterNg2ModuleBootstrap(moduleRef, upgrade, element, modules, config); ng1Injector = this._afterNg2ModuleBootstrap(moduleRef, upgrade, element, modules, config);
}); });
return upgrade; return upgrade;
@ -443,6 +447,9 @@ export class UpgradeAdapter {
* document.body.innerHTML = '<app></app>' * document.body.innerHTML = '<app></app>'
* adapter.bootstrap(document.body, ['myExample']); * adapter.bootstrap(document.body, ['myExample']);
*``` *```
*
* @deprecated Use NgModules and `new UpgradeAdapter(ng2AppModule)` to configure top-level
*providers
*/ */
public addProvider(provider: Type|Provider|any[]|any): void { this.providers.push(provider); } public addProvider(provider: Type|Provider|any[]|any): void { this.providers.push(provider); }