[英]How to dynamically update template in component of Angular 2, Ionic 2
I have a component that gets its template from a remote url. 我有一个从远程URL获取其模板的组件。 I want to have a function on event which does something to request the component's template again and change the already rendered template.
我想在事件上添加一个函数,该函数可以执行一些操作以再次请求组件的模板并更改已渲染的模板。
@Component({ selector: 'cartpage-blocks-cartpage', templateUrl: '/url/to/romote/server/template' }) export class CartPageBlocksCartPage{ /** * Constructor of class * * @param events - events controller */ constructor( public events: Events ){ this.events.subscribe('reload-component-template', () => { /* Do something to reload template */ }); } }
How to request component template again and recompile the template to a newer updated one? 如何再次请求组件模板并将模板重新编译为更新的模板? I want it because, after my user is authorised, my template automatically changes and I want to show changes dynamically by calling an event.
我想要它是因为在授权用户之后,我的模板会自动更改,并且我想通过调用事件来动态显示更改。
I think they have never intend to add dynamic swapping for templates, instead their recommended way is to have variables to swap the different views. 我认为他们从来没有打算为模板添加动态交换,而是建议的方法是让变量交换不同的视图。
A better way is to work with your routes and creating specific component templates with conditional statements to show/hide different features. 更好的方法是使用您的路线,并使用条件语句创建特定的组件模板以显示/隐藏不同的功能。 Make sure you set up AuthGuards to make sure that your app only allows authorised users.
确保设置AuthGuard,以确保您的应用仅允许授权用户使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.