2

Is it possible to load an Angular2 application or component via http? What I'm looking for is something like that:

Template:

<app-local></app-local> <app-http></app-http>

AppComponent of app-local:

[...] loadComponent("http://someurl/", "http-app"); [...]

where app-http is an app or component from another url. After calling "loadComponent" the placeholder "http-app" should be replaced by the application. I don't know how to describe it better, but I hope someone understands what I'm talking about.

julianpoemp
  • 1,965
  • 3
  • 14
  • 29

2 Answers2

4

In AngularJS 2 you can Eagerly or Lazy Load Modules, not Components, perhaps you already know this, Lazy loading the Module will satisfy your goal. The module could just contain one Component.

However you may find you have to Lazy Load the Module from the same URL as the AngularJS 2 app was requested from.

Here is more on Lazy Loading Modules in AngularJS 2: https://angular-2-training-book.rangle.io/handout/modules/lazy-loading-module.html

Brian Ogden
  • 18,439
  • 10
  • 97
  • 176
  • thank you, but in this solution I have to load the module from a local path. Perhaps using iframes could be the only solution for this task... – julianpoemp Mar 16 '17 at 20:19
  • @geronimo678 You can Lazy Load from a local url, again if you are trying to load Module parts from different urls I am not sure Angular 2 supports that. Either way, I would bet you have not solved your problem and you are making things too complex because you desire to Lazy load app pieces from different URLs in the first place – Brian Ogden Mar 16 '17 at 22:59
  • Yes, you're right my problem is actually not solved. I'm thinking about the possibility of lazy load components from a local url instead of a remote url. If this is possible in my situation that would be more secure than load from a remote url. – julianpoemp Mar 19 '17 at 11:52
1

You can use iFrame for this task.

John Doe
  • 3,794
  • 9
  • 40
  • 72