我创建了一个angular-cli包含AppComponent的项目,如下所示:
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'app works!';
}
Run Code Online (Sandbox Code Playgroud)
和app.component.html一样
<h1>
Good Morning, {{title}}
</h1>
Run Code Online (Sandbox Code Playgroud)
因此,当我使用ng build它生成它时会生成一些像这样的文件./dist/main.bundle.js,其中包含一些代码,如下所示 -
/* 586 */
/***/ function(module, exports) {
module.exports = "<h1>\n Good Morning, {{title}}\n</h1>\n"
/***/ },
/* 587 */
Run Code Online (Sandbox Code Playgroud)
这意味着,在构建时,编译器/ bundle-er正在读取html文件并将它们连接到生成的js文件中.
但在我的情况下,html也是动态的,内容驱动的是服务器端.可以说,我的模板文件不是html,而是app.component.jsp,并且完全驻留在一些不同的服务器或文件夹上.
此JSP文件有时会返回<h1>Good Morning, {{title}}</h1>
,有时还<h1>Good Afternoon, {{title}}</h1>取决于当前的服务器时间.
如何实现这一功能?
我的理解是,我需要定义某种加载器函数说: loadDynamicTemplate(template_url) …
我在angular1中有一个应用程序,我使用jquery在我的HTML元素中加载外部页面.这是我的容器元素的html:
<div id="externalContainer" class="text-center">
</div>
Run Code Online (Sandbox Code Playgroud)
我使用以下脚本加载外部页面.
$( "#externalContainer" ).load( myExternalPageLink );
Run Code Online (Sandbox Code Playgroud)
现在这似乎不适用于angular4,专家可以指导我如何在angular4中实现此功能?