简体   繁体   中英

How to dynamically update template in component of Angular 2, Ionic 2

I have a component that gets its template from a remote 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM