Modals (or others) with component as content does not trigger ngOnChanges
See original GitHub issueThis is really nice:
const modalRef = this.modalService.open(NgbdModalContent);
modalRef.componentInstance.name = 'World';
Anyway this does not trigger ngOnChanges()
when we set the input “name” but this lifecycle-hook are a crucial feature of Angular components.
Please consider this as a feature request. Also i am looking for a workaround to trigger ngOnChanges manually.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:4
- Comments:6 (2 by maintainers)
Top Results From Across the Web
ngOnChanges not trigger when setting property directly
When you set the component instance's values directly, it will not trigger an ngOnChanges. ngOnChanges is triggered when the value binding ...
Read more >Testing Components – Testing Angular
Introduction to testing Angular Components with Angular's TestBed. ... triggerEventHandler does not simulate event bubbling or any other ...
Read more >Angular / Angular guidelines and best practices / Testing
Writing good quality tests for critical functionalities is an important step in quality assurance. We do not recommend not writing any tests ...
Read more >Heading Off 11 Common Angular Application Design, Best ...
Often this is seen with modal windows, application level alerts, or other event ... This is not to say the dumb components have...
Read more >Angular View Updating Using Observables, Behavior Subject ...
What if the form is in a child component, say in a modal? Oh shoot. No worries! This is when event emitters come...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
private cd_interval_fn: any; constructor(private cdref: ChangeDetectorRef ) { this.cdref.detach(); const This = this; this.cd_interval_fn = setInterval(() => { This.cdref.detectChanges(); }, 500); } ngOnDestroy() { clearInterval(this.cd_interval_fn); this.cdref.detach(); }
This works for me.
@IAfanasov , your proposed workaround didn’t work for me.
ngOnChanges
still wouldn’t get triggered. 😕The only workaround I got working was to wrap the component with
ngOnChanges
in another component that only forwards the binding.Like this:
Using Angular v7.2.15 (if ever that changes anything)