[英]How to add a HTML partial without a component inside a view in Angular2
我有一个组件及其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
的Directive
,它将为您完成工作..该Directive
将加载html文件,然后将其粘贴到DOM
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.