我有一个组件及其 HTML 文件。
组件:
hello-world.component.ts
import {Component} from 'angular2/core';
@Component({
selector: 'hello-world',
templateUrl: 'hello-world.html'
})
export class HelloWorld {
yourName: string = '';
}
模板:
hello-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
关于html - 如何在 Angular2 的 View 中添加没有组件的 HTML 部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40816903/