Dynamically created component model is not being reflected in the template on change
See original GitHub issueπ bug report
Affected Package
The issue is caused by package 'not sure'Is this a regression?
NoDescription
Dynamically created component model is not being bind to the view on model change. Reproduced the issue in below stackblitz project.π¬ Minimal Reproduction
https://stackblitz.com/edit/angular-tyhfkuπ Your Environment
Angular Version:
@angular/common7.2.5
@angular/compiler7.2.5
@angular/core7.2.5
@angular/forms7.2.5
@angular/platform-browser7.2.5
@angular/platform-browser-dynamic7.2.5
@angular/router7.2.5
core-js2.6.5
rxjs6.4.0
zone.js0.8.29
Anything else relevant?
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
Detect data changes on dynamic component is not working
Its not possible for a dynamically created component to be aware of changes. What worked for me was triggering change detection at the...
Read more >Loading Components Dynamically in an Angular App
A tutorial that shows how to create an Angular app with dynamic component loading.
Read more >Dynamic component loader - Angular
Component templates are not always fixed. An application might need to load new components at runtime. This cookbook shows you how to add...
Read more >Form validation of dynamically created input elements does ...
When you create a simple form with two text input elements being "required" and the second input is created by a dynamic sub...
Read more >Dynamically-rendered ASP.NET Core Razor components
The {COMPONENT} placeholder is the dynamically-created component type. IRefreshable is an example interface provided by the developer forΒ ...
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 Free
Top 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
No, it shouldnβt since config.active = true and view.oldValue[i] is also true so component will never receive updated value. What you can do it to use two-way binding and donβt mutate state. https://stackblitz.com/edit/angular-5qansx?file=src/app/hero.component.ts
@azimsodikov I suspect youβre expecting that after you changed the
active
property by clicking on the line insideapp-section
component and then clicked on theRestore State
button it should revert your primitive value to the default value, right?The first we can try is to to remove dynamic loading https://stackblitz.com/edit/angular-zsphvy?file=src%2Fapp%2Fsection.component.ts
As we can the dynamic component is not a problem here.
Now, letβs think when ngOnChanges should be called.
It should be called when Angular (re)sets data-bound input properties.
parent component
child component
The first time the ngOnChanges is called is when we set default value so it changes from undefined to false.
Note that we deal with primitive value here. So we have AppSectionInstance.active = false; view.oldValue = false;
Now you click on the line and change AppSectionInstance.active to false. view.oldValue remains the same. And when youβre trying to update config Angular canβt recognize the change since new value(false) is not changed(view.oldValue = false)