在一个角度内显示或渲染另一个角度内的最佳方法是什么?

时间:2019-06-09 09:23:53

标签: angular typescript angular7

我在角度7中创建了一个新组件

ng g c mynewcomp

包含从后端呈现数据并在HTML中显示的功能。

但是我想将新视图/组件放置在另一个现有组件中

例如,用户可以在需要显示我的新组件内容的情况下查看旧组件中的内容,

在不影响新旧组件的情况下执行此操作的最佳做​​法是什么

3 个答案:

答案 0 :(得分:0)

在旧组件html中,放入新组件的选择器,如下所示:

<app-mynewcomp></app-mynewcomp>

答案 1 :(得分:0)

为了满足用户可以查看旧组件中的内容的要求,根据该要求,需要显示我的新组件内容。 ,

在旧组件html页面的末尾添加新组件的选择器

<app-mynewcomp></app-mynewcomp>.

应用此功能后,应用程序将以通常的方式在顶部显示旧内容,而在新内容下方显示n。

答案 2 :(得分:0)

创建两个组件,   1. oldComponent   2. newComponent

app.module.ts

import { oldComponent } from './oldComponent.component';
import { newComponent } from './newComponent.component';

declarations: [
    oldComponent,
    newComponent 
  ]

在app.component.html中包含两个组件选择器 app.component.html

<oldComponent></oldComponent>

oldComponent.component.html

<p> oldComponent works! </p>
<newComponent></newComponent>

请参考下面的slackblitz示例,我创建该示例是为了满足您的需求 slackblitz example