Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Am I able to change templateUrl in angular 2 dynamically?

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.

like image 891
Lolo. Avatar asked Nov 20 '15 09:11

Lolo.


Video Answer


1 Answers

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.

like image 158
binariedMe Avatar answered Sep 21 '22 01:09

binariedMe