美文网首页Angualr
angular4 动态绑定class

angular4 动态绑定class

作者: 追逐繁星的阿忠 | 来源:发表于2018-12-14 16:56 被阅读57次

问题场景:

222.png

请问一下 我想在1的位置添加一个和下标关联的class 应该怎么操作?



有效的方案

333.png
444.png

特别说明:

带中括号后面就不要带大括号 反之就要带

虚拟dom节点上不能帮属性 只能绑逻辑

ng-container标签下层加一个div 把class放那里面

{}里面的东西会去运算的

另外死的东西用da括号括起来

DEMO展示

<ng-container *ngIf="v.commissions">
                        <tr *ngFor="let v1 of v.commissions;let num=index">
                            <td>{{v1.category_name}}</td>
                            <td>{{v1.total_number}}</td>
                            <td>{{v1.total_commissions}}</td>
                            <ng-container *ngIf="TOP5 === true">
                                <td style="position: relative;" class="{{'top5-'+v1.topId}}">
                                    <div *ngFor="let v2 of v1.top5" >{{v2.name}}</div>
                                    <div *ngIf="v1.top5.length >4" class="ori-text" style="position: absolute;right: 10px;top: 2px" (click)="showMore(v1.topId);">查看更多</div>
                                </td>
                                <td class="{{'top5-'+v1.topId}}"><div *ngFor="let v2 of v1.top5">{{v2.count}}</div></td>
                                <td class="{{'top5-'+v1.topId}}"><div *ngFor="let v2 of v1.top5">{{v2.amount}}</div></td>
                                <td class="{{'top5-'+v1.topId}}">
                                    <a href="javascript:void(0)"
                                       style="display: block"
                                       *ngFor="let v2 of v1.top5"
                                       [routerLink]="['/order/detail', v2.order_id]"
                                       class="ori-text">查看订单</a>
                                </td>
                            </ng-container>
                            <ng-container *ngIf="TOP5 === false">
                                <td class="{{'top6-'+v1.topId}}"><div *ngFor="let v2 of v1.topAll">{{v2.name}}</div></td>
                                <td class="{{'top6-'+v1.topId}}"><div *ngFor="let v2 of v1.topAll">{{v2.count}}</div></td>
                                <td class="{{'top6-'+v1.topId}}"><div *ngFor="let v2 of v1.topAll">{{v2.amount}}</div></td>
                                <td class="{{'top6-'+v1.topId}}">
                                    <a href="javascript:void(0)"
                                       style="display: block"
                                       *ngFor="let v2 of v1.topAll"
                                       [routerLink]="['/order/detail', v2.order_id]"
                                       class="ori-text">查看订单</a>
                                </td>
                            </ng-container>
                        </tr>
                    </ng-container>

<td>{{v1.category_name}}</td>
                            <td>{{v1.total_number}}</td>
                            <td class="ori-text">{{v1.total_commissions.toFixed(2)}}</td>
                            <td style="position: relative;" [ngStyle]="{'display': tempId === v1.topId ? 'none' : '' }">
                                <div *ngFor="let v2 of v1.top5" >{{v2.name}}</div>
                                <div *ngIf="v1.top5.length >4" class="ori-text" style="position: absolute;right: 10px;top: 2px" (click)="showMore(v1.topId);">查看更多</div>
                            </td>
                            <td [ngStyle]="{'display': tempId === v1.topId ? 'none' : '' }"><div *ngFor="let v2 of v1.top5">{{v2.count}}</div></td>
                            <td  [ngStyle]="{'display': tempId === v1.topId ? 'none' : '' }"><div *ngFor="let v2 of v1.top5">{{v2.amount}}</div></td>
                            <td  [ngStyle]="{'display': tempId === v1.topId ? 'none' : '' }">
                                <a href="javascript:void(0)"
                                   style="display: block"
                                   *ngFor="let v2 of v1.top5"
                                   [routerLink]="['/order/detail', v2.order_id]"
                                   class="ori-text">查看订单</a>
                            </td>

                            <td [ngStyle]="{'display': tempId === v1.topId ? '' : 'none' }"><div *ngFor="let v2 of v1.topAll">{{v2.name}}</div></td>
                            <td [ngStyle]="{'display': tempId === v1.topId ? '' : 'none' }"><div *ngFor="let v2 of v1.topAll">{{v2.count}}</div></td>
                            <td [ngStyle]="{'display': tempId === v1.topId ? '' : 'none' }"><div *ngFor="let v2 of v1.topAll">{{v2.amount}}</div></td>
                            <td [ngStyle]="{'display': tempId === v1.topId ? '' : 'none' }">
                                <a href="javascript:void(0)"
                                   style="display: block"
                                   *ngFor="let v2 of v1.topAll"
                                   [routerLink]="['/order/detail', v2.order_id]"
                                   class="ori-text">查看订单</a>
                            </td>

相关文章

  • angular4 动态绑定class

    问题场景: 请问一下 我想在1的位置添加一个和下标关联的class 应该怎么操作? 有效的方案 特别说明: 带中...

  • vue 动态绑定class,style

    动态绑定class 动态绑定style

  • vue03

    v-bind动态绑定class(对象语法) v-bind动态绑定class(数组语法) v-bind动态绑定sty...

  • Class 与 Style 如何动态绑定?

    Class 与 Style 如何动态绑定? Class 可以通过对象语法和数组语法进行动态绑定: 对象语法: 数组...

  • Vue.js

    动态绑定class : class:[ name?success:error,name?success:error...

  • 跟我一起学Python(六)

    __ slots __ 如何在外部给class绑定方法? 动态绑定允许我们在程序运行的过程中动态给class加上功...

  • 动态绑定style 和 class

    开发中用到的动态修改界面的功能,这里记录下: class 动态绑定 style 动态绑定 这里说明下:动态修改主要...

  • Vue系列之『满足多数需求的基本使用』

    首先创建一个简单的vue应用 class绑定——动态地切换class 在:class上绑定一个对象 在:class...

  • 小程序常用知识点

    循环嵌套:修改item的名称 动态绑定class

  • Vue入门:v-bind

    本篇为Vue的基础篇,主要关于 v-bind: class与style的动态绑定。 1. 绑定 class 的几种...

网友评论

    本文标题:angular4 动态绑定class

    本文链接:https://www.haomeiwen.com/subject/jjighqtx.html