How to use angular 2 upgradeAdapter.upgradeNg1Component?

I am pretty sure that I am missing something fundamental here.

I started using the ng2 update adapter before RC5 to start porting the ng1 application to ng2. And before, when you declared the directives that the component used directly on the component, everything is correctly connected and it makes sense.

But now I'm trying to port my hybrid app to Angular 2 Final, and all of NgModule's work confuses the hybrid app when it comes to dependencies.

To create an update adapter, I need to pass the Ng2 module to it, which I want to use in a hybrid application. It's great. But this means that the Ng2 module must be fully defined BEFORE I create the update adapter, right? If this is the case, then how can I use the update adapter that has not yet been created to update the ng1 components for use in the ng2 module (which must be created before the adapter is created) ???

FYI, on the other hand, is good - I have a typescript module that lowers all the top-level ng2 components that I need to use in ng1 (in the ui-router configuration), and that the typescript module loads after updating the update adapter and the Ng2 module containing my components, for lowering.

So what am I missing? How to use ng1Component update adapter update functionality?

. , , , , ng2.

+4
1

, Angular . forwardRef() UpgradeAdapter:

import {NgModule, forwardRef} from '@angular/core';
import {UpgradeAdapter} from '@angular/upgrade';

const adapter = new UpgradeAdapter(forwardRef(() => AppModule));

@NgModule({
    declarations: [
         adapter.upgradeNg1Component('my-component');
    ]
})
class AppModule {
}

// now call adapter.bootstrap()
+2

Source: https://habr.com/ru/post/1657028/


All Articles