如何在Angular2中的视图中添加没有组件的HTML部分

前端之家收集整理的这篇文章主要介绍了如何在Angular2中的视图中添加没有组件的HTML部分前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个组件及其 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

猜你在找的Angularjs相关文章