question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Downgraded component not reacting to user events in a lazy loaded module using downgradeModule approach

See original GitHub issue

I’m submitting a…


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report  
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior

Downgraded component that is part of a lazy loaded module is not reacting to user events when using downgradeModule approach.

Expected behavior

It should work normally as if it’s part of the main module / not lazy loaded.

Minimal reproduction of the problem with instructions

Now:

  • open developer tools in chrome, go to sources tab and locate static.js
  • put a breakpoint on line 526 (var doDowngrade = function (injector) {) and reload the page
  • on first hit app-root component is initialized and you can observe that needsNgZone value is true
  • on second hit, it’s a component that is loaded from lazy loaded module but now needsNgZone is set to false.
  • If you set it’s value to true using console and continue - the component will work as expected. I mean clicking click to expand will work and reveal the text that is hidden with *ngIf

All the code related to the example can be seen in this commit: https://github.com/FDIM/angular-hybrid-lazy-load-example/commit/918d7504b73f1bda2863b94b7868bd535eacdc25

What is the motivation / use case for changing the behavior?

To make it possible to use downgradeComponent inside lazy loaded module with a workaround described here: #17490

In short the workaround is about setting $$$angularInjectorController on some parent (in e.g. route resolve) which forces downgrade component to use that value as injector and thus correctly locate the component. As I understand this is working OK when UpgradeModule is used, but not with downgradeModule.

I propose the following fix:

  • setting REQUIRE_INJECTOR_NEEDS_NG_ZONE variable to ?^^$$angularInjectorNeedsNgZone
  • using it as follows: image

This way it would be possible to extend previously mentioned workaround and force the variable to be true.

Environment

Angular version: 5.2.7

Browser: any

P.S. I would have used stackblitz for the example, but the lazy loading there is not working: https://stackblitz.com/github/fdim/angular-hybrid-lazy-load-example

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:12 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
FDIMcommented, Mar 19, 2018

I just tested it out, and if I pass propagateDigest: false it works in my example as well.

@gkalpak if you say otherwise, I’ll try to make a PR that will add another flag to the if you pointed out here that will check if downgradeModule is used

EDIT: I couldn’t resist and wanted to sleep well so I prepared a PR 😃

0reactions
angular-automatic-lock-bot[bot]commented, Sep 14, 2019

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

Read more comments on GitHub >

github_iconTop Results From Across the Web

downgradeModule - Angular
A helper function for creating an AngularJS module that can bootstrap an Angular module "on-demand" (possibly lazily) when a downgraded component needs to ......
Read more >
Using downgradeModule in conjunction with ... - Stack Overflow
So I have AngularJS bootstrap, load an Angular directive and its module first, so I can downgrade a migrated service and use it...
Read more >
Upgrading for performance - Angular
An important part of inter-linking dependencies is linking the two main modules together. This is where downgradeModule() comes in. Use it to create...
Read more >
Downgrading Angular 2 components to Angular 1 directives ...
If you have followed the steps in Connecting Angular 1 and Angular 2 with UpgradeModule, you should now have a hybrid application that...
Read more >
How to downgrade component in modular AngularJS ...
Hi,. I have a modular AngularJS app that is under upgrade to Angular 8 using the downgradeModule. I have upgraded a component which...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found