从外部URL加载Angular2模板 [英] Load Angular2 template from external URL
问题描述
是否可以从外部URL加载模板? 这是我目前正在尝试做的事情,但是Angular似乎忽略了它而没有引发任何错误,并且页面只是无限期地继续加载.
Is it possible to load templates from external URLs? This is what I'm currently trying to do, but Angular seems to be ignoring it without throwing any errors and the page just keeps on loading indefinitely.
@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
我可以直接访问,并且设置了CORS,以允许端口8080上的Dart应用程序与端口9091上的Kotlin应用程序进行通信.
http://localhost:9091/html/dashboard-page.html
I can access directly and CORS is setup to allow the Dart application on port 8080 to communicate with the Kotlin application on port 9091.
我正尝试根据帐户配置文件加载不同的HTML模板-不同的帐户将看到Kotlin代码为不同的HTML模板提供服务.
I'm trying to load different HTML templates depending on the account profile - different accounts will see different HTML templates being served by the Kotlin code.
我是否可以完成Angular2加载外部模板文件的工作?
I this something that can be done or is not possible for Angular2 to load external template files?
推荐答案
templateUrl
字符串必须是编译时间常数,并且在运行pub build
时会读取.
即使它可以在构建时从HTTP
网址中读取,也无济于事
The templateUrl
string has to be a compile time constant and is read when pub build
is run.
Even if it could read from an HTTP
url at build time it wouldn't help a bit for
我正尝试根据帐户配置文件加载不同的HTML模板-不同的帐户将看到Kotlin代码为不同的HTML模板提供服务.
I'm trying to load different HTML templates depending on the account profile - different accounts will see different HTML templates being served by the Kotlin code.
改为使用*ngIf
或ngSwitch
或动态添加的组件.
Use *ngIf
or ngSwitch
or dynamically added components instead.
这篇关于从外部URL加载Angular2模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!