简体   繁体   English

Angular ng-class和bootstraps CSS

[英]Angular ng-class and bootstraps css

I am using 'table-striped' from bootstrap and 'ng-class' from angularjs to present a table. 我正在使用bootstrap中的'table-striped'和angularjs中的'ng-class'来呈现表。 The idea is to show striped table and when click on one row, it is highlighted. 这个想法是显示条形表,当单击一行时,它会突出显示。

The following is copied from chrome as a result of 'click' on odd row. 由于在奇数行上“单击”,因此从chrome复制了以下内容。

<div class="table-responsive" id="Destination">
    <table class="table table-striped" id="destinationTable">
    <thead>
...
    </thead>
    <tbody>
        <!-- ngRepeat: entity in destinations -->
        <tr ng-repeat="entity in destinations" ng-click="setName()" ng-class="{'highlight' : destinationName == entity.name}" class="ng-scope highlight">

    </tbody>
    </table>
</div>

As you can see, "class="ng-scope highlight" is already generated by angularjs on that row, but it just not take effect. 如您所见,angularjs已经在该行上生成了“ class =“ ng-scope Highlight”,但是它没有生效。

Also it is strange to me the same code works well for even row. 同样令我惊讶的是,相同的代码对于偶数行也能很好地工作。 I don't see the difference of the html between that from odd row click and that from the even row click. 我看不到奇数行单击和偶数行单击之间的html区别。

In the "bootstrap.css", it has, 在“ bootstrap.css”中,

.table-striped > tbody > tr:nth-of-type(odd) {background-color: #f9f9f9;}

I am wondering this class in applied to overwrite the one I want, the 'highlight'. 我想知道这个类是否可以覆盖我想要的那个“亮点”。

Is there anyway to solve it? 反正有解决办法吗?

I faced the same issue and it seemed to have to do with the css in the table striping. 我遇到了同样的问题,它似乎与表条中的css有关。

A workaround would be to do the following: 一种解决方法是执行以下操作:

  1. Either use ng-style directive 使用ng-style指令

  2. Use !important in the css of the class attribute you want to show ( for example background-color: #dff0d8 !important; for your highlight class ) 在要显示的类属性的css中使用!important(例如,对于高亮显示类,例如background-color:#dff0d8!important;)

    Item #1 is probably the better way to go here but both should work. 项目#1可能是到达这里的更好方法,但是两者都应该起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM