从外部URL加载Angular2模板

编程入门 行业动态 更新时间:2024-10-22 22:58:50
本文介绍了从外部URL加载Angular2模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

是否可以从外部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: 'localhost:9091/html/dashboard-page.html', directives: const [], pipes: const [] ) class DashboardPage implements AfterContentInit {

localhost:9091/html/dashboard-page.html我可以直接访问,并且设置了CORS,以允许端口8080上的Dart应用程序与端口9091上的Kotlin应用程序进行通信.

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模板

本文发布于:2023-11-15 10:31:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1593635.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:加载   模板   URL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!