如何使用ng-repeat设置动态创建的宽度

时间:2021-10-06 20:19:54

I am creating dynamic headers of a table like this:

我正在创建一个像这样的表的动态标题:

<thead>
    <tr>
        <th width="5%" class="shrink">
            <input type="checkbox" id="selectedAll" ng-model="selectedAll" ng-click="selectAll()" />
        </th>
        <th class="header" data-href="" rel="tooltip" title="" ng-repeat="header in tableHeaders" width="header.width">
            <a style="cursor: pointer;" ng-click="Search(1,header.colName,
                    sorting.reverseSort=!sorting.reverseSort)">
                        {{header.name}}
                        <span ng-show="orderBy == header.colName">
                            <i ng-class="sorting.reverseSort ? 'fa fa-sort-asc' : 'fa fa-sort-desc'"></i>
                        </span>
                    </a>

        </th>
        <th width="10%" class="last shrink"></th>
    </tr>
</thead>

But “header.width” is not applying as it is in a same element as ng-repeat.

但是“header.width”没有应用,因为它与ng-repeat在同一个元素中。

So what is work around for this?

那么解决这个问题的方法是什么?

Please guide me.

请指导我。

Thank you.

谢谢。

2 个解决方案

#1


3  

Use curly braces:

使用花括号:

<th class="header" data-href="" rel="tooltip" title="" ng-repeat="header in tableHeaders" width="{{header.width}}">

#2


1  

Try this

尝试这个

 <th title="" ng-repeat="header in tableHeaders" ng-style="{'width': header.width}">

#1


3  

Use curly braces:

使用花括号:

<th class="header" data-href="" rel="tooltip" title="" ng-repeat="header in tableHeaders" width="{{header.width}}">

#2


1  

Try this

尝试这个

 <th title="" ng-repeat="header in tableHeaders" ng-style="{'width': header.width}">