2016-11-26 116 views
3

我有一個組件及其HTML文件。如何在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> 

現在,我想包括template.html文件中hello-world.html。我怎樣才能做到這一點。

在Angular1我用來做什麼,

<div ng-include src="'template.html'"></div> 

我怎樣才能做到這一點在Angular2?我對Angular2非常陌生。

我在很多地方搜索了這個問題,每個人都給出了一個包含組件的答案。但沒有得到我需要的解決方案。

回答

1

簡而言之:現在還不可能開箱即用。

您可以創建一個Directive像老ng-include這將做的工作對你.. 這Directive將加載HTML文件,然後將其粘貼到DOM

相關問題