我有一个组件及其
HTML文件.
零件:
你好,world.component.ts
import {Component} from 'angular2/core'; @Component({ selector: 'hello-world',templateUrl: 'hello-world.html' }) export class HelloWorld { yourName: string = ''; }
模板:
你好,world.html:
<label>Name:</label> <h1>Hello {{yourName}}!</h1>
现在,我有其他没有组件的html template.html,例如它包含,
template.html
<h1>Welcome to template file</h1> <p> This is an example file </p>
现在,我想在hello-world.html中包含template.html文件.我怎样才能做到这一点.
在Angular1我曾经做过,
<div ng-include src="'template.html'"></div>
我怎么能在Angular2中做到这一点?我是Angular2的新手.
解决方法
简短:尚未开箱即用.
您可以创建一个类似旧的ng-include的指令,它将为您完成工作.该指令将加载html文件,然后将其粘贴到DOM