【问题标题】:Add Attribute to multiple subcomponent Tags为多个子组件标签添加属性
【发布时间】:2018-03-27 14:18:50
【问题描述】:

我使用使用 Material Design 的 Alfresco ADF。他们有一个数据表组件,它实际上使用了 Angular 材质表。

现在为了实现拖放功能,我需要在每个mat-rowtag 上添加draggable="true"

我该如何做到这一点?我听说您应该使用 Renderer2 和 ElementRef,以便访问 DOM 元素并更改其属性。

或者还有其他方法吗?

【问题讨论】:

    标签: javascript html angular angular-material elementref


    【解决方案1】:

    在角度材质中,您可以像这样定义table,它允许您将属性添加到mat-row 元素。

    <mat-table #table [dataSource]="dataSource">
    
        <ng-container matColumnDef="myColumn">
          <mat-header-cell *matHeaderCellDef> My Column </mat-header-cell>
          <mat-cell *matCellDef="let element">
              Some content...
          </mat-cell>
        </ng-container>
    
        <mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
        <mat-row draggable="true" *matRowDef="let row; columns: displayedColumns;"></mat-row>
    
      </mat-table>
    

    Example result

    【讨论】:

    • 抱歉,怎么办? #table 已经可用了吗?正如我所说,我对 Alfresco ADF 多了一层抽象。他们有一个组件,然后使用材料表。所以我没有直接访问权限
    • 我明白了。如果您想坚持使用 Alfresco 抽象,您可以尝试使用 table.getElementsByTagName("mat-row") 之类的东西获取所有 mat-row 元素,然后遍历数组并执行 item.setAttribute("draggable", "true")
    猜你喜欢
    • 2013-07-04
    • 1970-01-01
    • 2022-09-24
    • 1970-01-01
    • 2019-09-19
    • 1970-01-01
    • 2017-09-17
    • 2018-12-29
    • 1970-01-01
    相关资源
    最近更新 更多