加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

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

发布时间:2020-12-17 17:08:27 所属栏目:安全 来源:网络整理
导读:我有一个组件及其 HTML文件. 零件: 你好,world.component.ts import {Component} from 'angular2/core';@Component({ selector: 'hello-world',templateUrl: 'hello-world.html'})export class HelloWorld { yourName: string = '';} 模板: 你好,world.htm
我有一个组件及其 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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读