6

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.

Lolo.
  • 434
  • 2
  • 6
  • 17
  • This is a out of date question. Angular only have rc version when I asked this question. Now, you have other ways to update the component template. – Lolo. Feb 07 '21 at 03:35

1 Answers1

7

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.

Community
  • 1
  • 1
binariedMe
  • 4,309
  • 1
  • 18
  • 34