在角度对话框中注入组件

时间:2017-11-09 20:15:01

标签: angular angular-material2

是否可以创建通用对话框并在必要时注入不同的组件。

在示例中,我有对话框并注入了组件{​​{1}}:

first-component

或者,如果我想,我可以重用对话框并注入另一个组件:

<dialog>
 <first-component></first-component>
</dialog>

我们能用尖角材料点头吗?

1 个答案:

答案 0 :(得分:1)

有多种方法可以做到这一点。如果您在自己的UI库中需要它,您可能正在寻找<ng-content>,一个占位符 - 角度 - HTML标记,可以被任何内容(-Child)替换,该内容从父代传递 - 组件层次结构。参考:https://angular.io/api/core/ContentChild

或者,如果您位于域组件中并且具有固定数量的可能内容,则可以使用<child-component *ngIf="condition; else #otherComponent">或两种以上的可能性*ngSwitchCase

或者,如果您希望通过网址控制内容,则可以使用<router-outlet>;见https://angular.io/guide/router

相关问题