Download Angular2 template from external url

Can I load templates from external URLs? This is what I'm trying to do now, but Angular seems to ignore it without causing any errors, and the page just keeps loading endlessly.

@Component( selector: 'dashboard-page', //templateUrl: '../templates/dashboard-page.html', templateUrl: 'http://localhost:9091/html/dashboard-page.html', directives: const [], pipes: const [] ) class DashboardPage implements AfterContentInit { 

http://localhost:9091/html/dashboard-page.html I can access directly, and CORS is configured so that the Dart application on port 8080 communicates with the Kotlin application on port 9091.

I'm trying to load different HTML templates depending on the account profile - different accounts will see different HTML templates served by Kotlin code.

Am I something that is possible or impossible for Angular2 to load external template files?

+6
source share
1 answer

The string templateUrl must be a compile-time constant and read when pub build starts. Even if he could read from the HTTP url during build, this would not help for

I'm trying to load different HTML templates depending on the account profile - different accounts will see different HTML templates served by Kotlin code.

Use *ngIf or ngSwitch or dynamically added components.

+2
source

Source: https://habr.com/ru/post/1012874/


All Articles