【问题标题】:How to render same component multiple time in material dialog in angular 10+?如何在角度 10+ 的材质对话框中多次渲染相同的组件?
【发布时间】:2022-07-26 21:51:14
【问题描述】:

组件:OpenMultiTimeComponent

选择器:'open-multi-time'

需要以下情况的解决方案,

  1. 打开对话框 - 加载 OpenMultiTimeComponent 组件。
  2. 打开另一个对话框 - 加载 TestComponent 组件。
  3. 在 TestComponent 中打开 OpenMultiTimeComponent。
<mat-dialog>  // Dialog 1
  <open-multi-time></open-multi-time> // Ref: 1

  <TestComponent> // Dialog 2
    <mat-dialog> 
      <open-multi-time></open-multi-time> // Ref: 2
    </mat-dialog>  
  </TestComponent> 
 
</mat-dialog>

问题:

  • 当我从 Ref: 2 组件更新任何变量时,它会从 Ref: 1 更新相同的变量。这是一个问题。

我们不想从 Ref:1 组件更新该变量。我们需要 Ref:1 和 Ref:2 的独特组件。

【问题讨论】:

    标签: angular angular-material angular10


    【解决方案1】:

    尝试为嵌套对话框添加新的对话框组件,因为您正在尝试打开同一个对话框。因为如果组件保持不变,那么成员变量将共享相同的行为。

    【讨论】:

    • 我们可以动态更新选择器名称吗?
    猜你喜欢
    • 2020-01-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-17
    • 2022-10-14
    • 2018-04-01
    • 1970-01-01
    • 2020-07-16
    相关资源
    最近更新 更多