[英]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.