代码之家  ›  专栏  ›  技术社区  ›  MattTreichel

获取ViewContainerRef中的元素而不知道其索引?

  •  1
  • MattTreichel  · 技术社区  · 7 年前

    https://angular.io/api/core/ViewContainerRef

    如果我想用角度的 ViewContainerRef move() 一个特定的孩子,我是否有更多的能力来选择它而不仅仅是使用 get(index) ? 我看到它有一个 indexOf(ViewRef) 方法,但我不知道如何得到 ViewRef 角度上没有从 视图容器ref 首先。

    例如,如果我创建一个如下所示的ViewContainerRef,我如何才能得到 视图参考 #button 元素以便我可以移动它,而不必确定其当前索引?有没有办法用这个按钮 ViewChild 在这种情况下?

      @ViewChild('list', {read: ViewContainerRef}) list: ViewContainerRef;
      @ViewChild('button') button;
    
    <div #list>
        ...
        <button #button>Toggle</button>
        ...
    </div>
    
    0 回复  |  直到 7 年前
    推荐文章