简体   繁体   English

Angular 6 在父组件中显示来自子组件的模板

[英]Angular 6 Show template from child in parent component

For an Angular 6 application I want to clean up my code and generalize some parts.对于 Angular 6 应用程序,我想清理我的代码并概括一些部分。

On a detail page in my application is have two main sections a summary and some more detailed stuff.在我的应用程序的详细信息页面上有两个主要部分,一个摘要和一些更详细的内容。 The summary is split up in three mat-cards.摘要分为三张垫子卡片。 And the detailed part is a larger mat-card over the whole width of the page.详细部分是在整个页面宽度上的较大垫卡。 The summary part is for each type of detail page more or less the same.摘要部分对于每种类型的详细信息页面或多或少都相同。 The detailed page is for each type different.每种类型的详细页面都不同。

I want to create an overview component, this component handles all the logic (HTTP-calls, etc.).我想创建一个概览组件,该组件处理所有逻辑(HTTP 调用等)。 For the detailed section i want to create a custom component for each type, these components will handle the visualization (different charts, tables, etc.).对于详细部分,我想为每种类型创建一个自定义组件,这些组件将处理可视化(不同的图表、表格等)。 Till now no big problem.到现在都没什么大问题。

The problem I stubbled upon is that in one of the detail mat-cards there is custom visualisation specific for each type.我偶然发现的问题是,在其中一张细节垫卡中,每种类型都有特定的自定义可视化。 So now my question, is it possible to somehow show content from a child component into the parent.所以现在我的问题是,是否有可能以某种方式将子组件中的内容显示到父组件中。 I attached an image to clarify my situation.我附上了一张图片来说明我的情况。

Take a look at ng-content : https://scotch.io/tutorials/angular-2-transclusion-using-ng-content看看ng-contenthttps : //scotch.io/tutorials/angular-2-transclusion-using-ng-content

In your parent, you would include ng-content blocks with selectors that your child component would place content into.在您的父组件中,您将包含带有选择器的ng-content块,您的子组件会将内容放入其中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM