我有一个组件及其 HTML 文件。
成分:
hello-world.component.ts
import {Component} from 'angular2/core';
@Component({
selector: 'hello-world',
templateUrl: 'hello-world.html'
})
export class HelloWorld {
yourName: string = '';
}
Run Code Online (Sandbox Code Playgroud)
模板:
你好-world.html:
<label>Name:</label>
<h1>Hello {{yourName}}!</h1>
Run Code Online (Sandbox Code Playgroud)
现在,我有其他template.html没有组件的html ,例如它包含,
模板.html
<h1>Welcome to template file</h1>
<p> This is an example file </p>
Run Code Online (Sandbox Code Playgroud)
现在,我想将template.html文件包含在hello-world.html. 我怎样才能做到这一点。
在 Angular1 我曾经做过,
<div ng-include src="'template.html'"></div>
Run Code Online (Sandbox Code Playgroud)
我怎样才能在 Angular2 中做到这一点?我对 Angular2 很陌生。
我在很多地方搜索了这个问题,每个人都给出了一个有组件的答案。但没有得到我需要的解决方案。
简而言之:目前还不可能开箱即用。
您可以创建一个Directive类似的旧ng-include文件来为您完成工作。这Directive将加载 html 文件,然后将其粘贴到 DOM