I read the Angular 2 upgrade guide and successfully bootstrapped a hybrid app (ng1 as base code and now incrementally rewriting the components and services to ng2).
Now what I don't understand is how I can use 3rd party ng1 modules, let angular2 inject them into my HeaderComponent?
I just saw examples of upgrading providers and components, but I think I'm still confused abou the module concept in angular2 so I don't get how to upgrade ng1 modules. Someone can please enlighten me?
upgrade_adapter.ts
import {AppModule} from './app.module';
import {UpgradeAdapter} from '@angular/upgrade';
export const upgradeAdapter = new UpgradeAdapter(AppModule);
app.module.ts
// imports...
@NgModule({
imports: [
BrowserModule,
HttpModule
],
declarations: [
HeaderComponent
],
providers: [ MyService ]
})
export class AppModule { }
index.ts
import { upgradeAdapter } from './upgrade_adapter';
// more imports...
angular.module(MODULE_NAME, [
//...
])
// HeaderComponent uses a ng1 3rd party module, how to use that module in that component
.component('header', upgradeAdapter.downgradeNg2Component(HeaderComponent))
// adding some ng1 components...
.factory('myService', upgradeAdapter.downgradeNg2Provider(MyService));
// bootstrap the application
angular.element(document).ready(function () {
upgradeAdapter.bootstrap(document.body, [MODULE_NAME]);
});
EDIT:
The 3rd party module is written in JS.
lib/angular-modules/communication/index.js
var communicationModule = angular.module('communication', [])
.factory('communication', require('./communication.factory'));
module.exports = communicationModule.name;