search

Home  >  Q&A  >  body text

angular.js - angularjs中ng-class和class到底有什么区别,怎么用ng-class呢

angularjs中ng-class和class到底有什么区别,怎么用ng-class呢

淡淡烟草味淡淡烟草味2739 days ago725

reply all(3)I'll reply

  • PHPz

    PHPz2017-05-15 17:04:47

    ng-class sets the class based on key: value

    reply
    0
  • PHP中文网

    PHP中文网2017-05-15 17:04:47

    function ctr($scope){
       $scope.test =“classname”;
    }
    
    
    
    <p class=”{{test}}”></p>
    
    
    
    function Ctr($scope) { 
        $scope.isActive = true;
    }
    
    
    
    <p ng-class="{true: 'active', false: 'inactive'}[isActive]">
    </p>
    
    
    
    function Ctr($scope) { 
    
    }
    
    
    
    <p ng-class {'selected': isSelected, 'car': isCar}">
    </p>
    
    
    

    reply
    0
  • 滿天的星座

    滿天的星座2017-05-15 17:04:47

    I did a project today and found that there is another way to write, which cannot be learned from books.

    ng-class="{'IM_selected':(status.currTalkTo.FRIENDID==item.FRIENDID)}"
    

    This is the syntax of js, explained as follows: If status.currTalkTo.FRIENDID == item.FRIENDID is equivalent, IM_selected will be displayed, otherwise it will not be displayed. This syntax is often used in projects to obtain the current page.

    reply
    0
  • Cancelreply