我可以动态更改angular2中的templateUrl吗? [英] Am I able to change templateUrl in angular 2 dynamically?

查看:151
本文介绍了我可以动态更改angular2中的templateUrl吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想动态更改templateUrl,我已阅读 Angular中的动态模板URL 2 .是的,我可以在组件初始化之前更改模板.但是我想要的是,当我按下一个按钮并且更改了url时,我的html就被更新了,就像两种方式的数据绑定一样.

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;
}())

但是当更改"dynamicUrl"时,没有发生任何事情.我还使用dynamicComponentLoader再次加载我的组件,并且组件未更改.

But when change the "dynamicUrl", not thing happened. I also use dynamicComponentLoader load my component again and component is not changed.

推荐答案

到目前为止,您无法在angular 2(alpha 48版本)中做到这一点. 您可以参考: https://groups.google.com/forum/# !topic/angular/ROkKDHboWoA

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

还有一个类似的问题: templateURL中angular2中的动态模板

There is a similar question : Dynamic template in templatURL in angular2

由于他们似乎不打算包括此内容,因此您想编写自己的函数,以用动态内容填充div.或类似的属性指令.

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.

这篇关于我可以动态更改angular2中的templateUrl吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆