Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将htm模板包含在Angular 6上的另一个模板中_Javascript_Html_Angular_Typescript_Include - Fatal编程技术网

Javascript 将htm模板包含在Angular 6上的另一个模板中

Javascript 将htm模板包含在Angular 6上的另一个模板中,javascript,html,angular,typescript,include,Javascript,Html,Angular,Typescript,Include,实际上,我有一个包含所有代码的HTML文件。我想在多个文件上拆分此文件并将其包括在内 我该怎么做 非常感谢。 您需要编写第二个组件- 将此组件添加到您的App.module.ts- 如果您有业务逻辑,您也可以通过以下服务提供此功能: 假设您有以下html: <div class="componentA">ComponentA</div> <div class="componentB">ComponentB</div> ComponentA.htm

实际上,我有一个包含所有代码的HTML文件。我想在多个文件上拆分此文件并将其包括在内

我该怎么做

非常感谢。

  • 您需要编写第二个组件-
  • 将此组件添加到您的App.module.ts-
  • 如果您有业务逻辑,您也可以通过以下服务提供此功能:

假设您有以下html:

<div class="componentA">ComponentA</div>
<div class="componentB">ComponentB</div>
ComponentA.html

<div class="componentA">ComponentA</div>
ComponentB.html

<div class="componentB">ComponentB</div>

除了上面的答案,别忘了包括

import { Component } from '@angular/core';

在两个组件的ts文件中

我建议您阅读有关组件的内容:当您使用
ng generate component exampleComponent
True生成组件时,默认情况下会包含它,但如果您手动创建它,则必须自己添加它。
<div class="componentB">ComponentB</div>
<componentA></componentA>
<componentB></componentB>
import { Component } from '@angular/core';