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.

Custom Element output events not firing during initialization lifecycle hooks

See original GitHub issue

🐞 bug report

Affected Package

The issue is caused by package @angular/elements

Is this a regression?

No

Description

Event listeners on Custom Element component outputs don’t fire during ngOnChanges (initial call), ngOnInit, ngAfterViewInit, or ngAfterContentInit.

🔬 Minimal Reproduction

https://github.com/antch/angular-elements-lifecycle-hooks For both the Custom and Native element there is a list which should be appended with the fired events. For the native element, we can see the callback fires during initialization of the component, but this doesn’t happen for the Custom Element.

You can look in the console to see the execution of the lifecycle hooks.

The reproduction uses artifacts from a CI build associated with #36114.

🌍 Your Environment

Angular Version: Warning: This is a build off of CI assets, so this isn’t entirely accurate.


Angular CLI: 9.0.6
Node: 10.14.2
OS: darwin x64

Angular: 9.1.0-next.4
... animations, common, compiler, compiler-cli, core, elements
... forms, language-service, platform-browser
... platform-browser-dynamic, router
Ivy Workspace: Yes

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.900.6
@angular-devkit/build-angular     0.900.6
@angular-devkit/build-optimizer   0.900.6
@angular-devkit/build-webpack     0.900.6
@angular-devkit/core              9.0.6
@angular-devkit/schematics        9.0.6
@angular/cli                      9.0.6
@ngtools/webpack                  9.0.6
@schematics/angular               9.0.6
@schematics/update                0.900.6
rxjs                              6.5.4
typescript                        3.6.5
webpack                           4.41.2

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
gkalpakcommented, Jun 12, 2020

FYI, we had to revert the fix, because it turned out to be a breaking change. More specifically, if someone was using their own NgElementStrategy that did not initialize the events property before calling its connect() method (with @remackgeek’s ElementZoneStrategy being a common example), @angular/elements would break because it would try to subscribe to the strategy’s events while it was undefined.

Therefore this fix has to wait for v11, unless we can fix it in a non-breaking way (which I think is possible). I will update with more info in the coming days.

1reaction
antchcommented, Jun 12, 2020

Thanks for your continued work on these Elements issues @gkalpak!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Events Fired During the Rendering Lifecycle | Lightning Aura ...
When the component tree is ready, the init event is fired for all the components, starting from the child components and finishing in...
Read more >
Lifecycle hooks - Angular
Your application can use lifecycle hook methods to tap into key events in the lifecycle of a component or directive to initialize new...
Read more >
Learn the Lifecycle of a Web Component by Building a ...
The following is an exploration of the available lifecycle methods and how they could be used when creating a custom button component.
Read more >
Lifecycle Hooks in Web Components - Ultimate Courses
Custom Element Reactions are called with special care in order to prevent user's code from being executed in the middle of a delicate...
Read more >
Angular lifecycle hook after all children are initialized?
I ended up using the ngAfterViewInit() hook in the following way: ngAfterViewInit(){ //stuff that doesn't do view changes setTimeout(_=> ...
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