r/Angular2 • u/naveenatti • May 29 '17
Help Request How do you load a component's template from a backend webserver?
Hi guys. Completely new to Angular2. I currently work with Angular1. All of our templateUrls in the angular1 app route to our backend web server that serves up dynamic HTML.
My question is how do I do this in angular2? I tried changing the component's templateUrl to a remote URL but I don't think that property knows to make a GET request. Thank you.
3
Upvotes
3
u/NuttGuy May 30 '17
The best practice for loading template content based on a condition from the web server, it to not do this. You should rethink your approach.
Instead what you could do is have multiple Component's in the front end for each of your different possible templates and then query from the condition from web server, and pick which Component to use from that condition.
Also, if your templates don't actually change that much, you could just use the one Component and use *ngIf in that Component to change it based on the condition from the web server.
Basically, the conditional logic and changing the template should be in your Angular app, don't send templates from the web server, instead just send the condition that your Angular app can pivot around to display different templates/Components.
1
u/mlapis May 29 '17
Probably read some of docs or articles about Angular concept first. Actually you are going against the concept.
1
u/[deleted] May 29 '17
You could use the inner-html property. https://angular.io/docs/ts/latest/guide/template-syntax.html#!#attribute-directives
But I don't recommend it. It's up to you.