I want to change my templateUrl dynamically, I've read Dynamic template URLs in Angular 2. Yes, I can change my template before the component initialize. But what I want is when I hit a button and the url change, then my html is update, like two way data binding.
I try make to my component like this:
templateUrl: (function() {
return dynamicURl;
}())
But when change the "dynamicUrl", not thing happened. I also use dynamicComponentLoader load my component again and component is not changed.
There is no way you can do it in angular 2 (alpha 48 version) as of now. You can refer to : https://groups.google.com/forum/#!topic/angular/ROkKDHboWoA ,
https://github.com/angular/angular/issues/2753
There is a similar question : Dynamic template in templatURL in angular2
As it seems that they are not planning to include this, you would like to write your own function to populate the div with dynamic content. Or a similar attribute directive.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With