search

Home  >  Q&A  >  body text

css - How does AngularJS judge different situations and set different background colors? ?

For example:

Based on

<ul style="float: left;overflow:hidden;" ng-repeat='node in nodedata' >
            
            <li style="list-style-type:none;">
                
                <span  style="background:green;" uib-popover="{{node.nodeIndex|getNodeNameFliter}}" popover-trigger="mouseenter" type="button" class="btn btn-default dd breath_light" popover-placement="bottom">{{node.nodeIndex|getNodeNameFliter}}</span>  <i class="icon-chevron-right" style="margin-left:10px;color:green;font-size:20px;"></i>
            
            </li>
            
        </ul>

style="background:green;"`You can set red, yellow, green, and black according to different values ​​1, 2, 3, and 4 of node.status. How to implement black?

Waiting online, no one knows?

習慣沉默習慣沉默2796 days ago540

reply all(3)I'll reply

  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-05-15 17:06:11

    html code: using ng-style

    <ul style="float: left;overflow:hidden;" ng-repeat='node in nodedata'>
            <li style="list-style-type:none;">
                <span ng-style="setColor(node.status)" uib-popover="{{node.nodeIndex|getNodeNameFliter}}"
                      popover-trigger="mouseenter" type="button" class="btn btn-default dd breath_light"
                      popover-placement="bottom">{{node.nodeIndex|getNodeNameFliter}}</span>
                <i class="icon-chevron-right" style="margin-left:10px;color:green;font-size:20px;"></i>
            </li>
        </ul>
    

    js code:

    $scope.setColor = function (status) {
        var p = "";
        if (1 == status) {
            p = 'red';
        } else if (2 == status) {
            p = 'yellow';
        } else if (3 == status) {
            p = 'green';
        } else if (4 == status) {
            p = 'black';
        }
        return {"background-color": p};
    };

    reply
    0
  • 迷茫

    迷茫2017-05-15 17:06:11

    As far as I know, CSS does not have such a function. The most famous CSS is media query, which can select different CSS styles according to different screen sizes. I think a request like the one in question can only be realized with the cooperation of JS.

    reply
    0
  • ringa_lee

    ringa_lee2017-05-15 17:06:11

    Now there are actually some people who use inline styles
    That’s what I would do
    <style>
    .backstyel1{background:red}
    .backstyel2{background:yellow}
    .backstyel3{background:green}
    .backstyel4{background:black }
    </style>

     <span class="btn btn-default dd breath_light backstyel{{node.nodeIndex|getNodeNameFliter}}" uib-popover="{{node.nodeIndex|getNodeNameFliter}}" popover-trigger="mouseenter" type="button" class="btn btn-default dd breath_light" popover-placement="bottom">{{node.nodeIndex|getNodeNameFliter}}</span>  <i class="icon-chevron-right" style="margin-left:10px;color:green;font-size:20px;"></i>
            

    reply
    0
  • Cancelreply