New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[2.2.0-rc.0] AoT can't add UpgradeComponent to @NgModule.entryComponents #12756
Comments
same here |
@bourey is this one of the issues that you solved? |
No, I don' think either the sample app I put together or the one vsavkin recently updated use UpgradeComponent. |
Exactly. None of them upgrades an ng1 component. But there is an test case for this: |
Just tried it out with the new 2.2 release that has been released some moments ago. I'm still facing this issue. As currently we just have this test case and no running demo-app, I'm still wondering whether it is a bug or whether we (guojenman above and I) did something wrong. Can please anyone elaborate on this? |
I tried to reproduce the problem using
|
latest beta of webpack no longer appends "-loader" to loaders, so I'm updating webpack config in zip and re-uploading. stay tuned... |
Updated the original post with fixed webpack config. Also uploading on this post for convenience. |
First of all, you don't need the upgraded component to be listed in Still, AoT won't fully work, because the The same issue affects other lifecycle hooks, such as The easy (but verbose) work-around is to add the lifecycle hooks on the upgraded component yourself so they can be detected during AoT compilation: @Directive({...})
class ForUpgradeDirective extends UpgradeComponent {
constructor(...) { ... }
ngOnInit() { return super.ngOnInit(); }
// Same for ngDoCheck, ngOnChanges, ngOnDestroy
...
} I am not sure whether it is possible/desirable for the metadata collectors - used to...collect metadata about directives/components - to detect lifecycle hooks higher up in the prototype chain. (I suspect this has been discussed before. Maybe @alexeagle knows more.) |
It has been discussed - I just synced with @tbosch |
Thanks Georgios and Alex! That works for me perfectly. For some reason, the above mentioned test case also work without implementing those live-cycle-hooks. |
tl;dr
*: Technically, this is not necessary in some situations (e.g. when a scope is destroyed higher up in the hierarchy), but it is something that is outside the control of the upgraded component, so I would not recommend leaving It works, because the
So, depending on what features your ng1 component relies on, you might be able to get by with omitting some of the hooks. It goes without saying, that the above info is based on the current (v2.2.0) implementation of |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
I'm submitting a ... (check one with "x")
Current behavior
UpgradeComponent can not be added to entryComponents of @NgModule.
a) with JIT
b) with AoT
ERROR in ./_aot/module.ngfactory.ts
(79,7): error TS2304: Cannot find name 'ForUpgradeDirectiveNgFactory'.
If you remove "ForUpgradeDirective" from entryComponents in src/module.ts
c) with JIT
ng1: hello from ng1
ng2: hello from ng1
d) with AoT
ng1: hello from ng1
ng2:
Expected behavior
Should compile & render UpgradeComponent when added to @NgModule.entryComponents
Minimal reproduction of the problem with instructions
test-upgrade.zip
for a & b above
a) npm run jit
b) npm run aot
for c & d above, remove ForUpgradeDirective from entryComponents and again run
c) npm run jit
d) npm run aot
What is the motivation / use case for changing the behavior?
Can't upgrade ng1 components and use AoT at the same time
Please tell us about your environment:
Language: [ TypeScript 2.0.2]
Node (for AoT issues):
node --version
= v6.6.0The text was updated successfully, but these errors were encountered: