AngularJS - 使用ng-class指令切换类

时间:2016-08-29 07:13:29

标签: angularjs angularjs-directive ng-class

指令

headerView.addSubview(label)
headerView.addSubview(labelValue)
headerView.addSubview(btnExpand)
headerView.sendSubviewToBack(label)
headerView.bringSubviewToFront(btnExpand)
return headerView

此处首次点击,我看到正在应用scope.pauseClass = 'fa fa-pause'; scope.muteClass = 'fa fa-volume-on'; <button ng-click="doPlayOrPause(uniqId)"><i ng-class="pauseClass"></i></button> <button ng-click="doMute(uniqId)"><i ng-class="muteClass"></i></button> scope.doMute = function(){ var vlc = scope.getVLC("vlc"); if (vlc && vlc.playlist.isPlaying) { vlc.audio.toggleMute(); scope.controlClass = 'fa fa-volume-off'; }else{ scope.controlClass = 'fa fa-volume-on'; } } scope.doPlayOrPause = function(){ var vlc = scope.getVLC("vlc"); if(vlc){ if(vlc.playlist.isPlaying){ vlc.playlist.togglePause(); scope.controlClass = 'fa fa-play'; }else{ vlc.playlist.play(); scope.controlClass = 'fa fa-pause'; } } } 并显示静音图标,但再次点击该按钮时,请勿切换课程。

  1. 如何使用ng-class指令切换类?
  2. 如何使用多个类创建一个函数 ng-class指令并将其称为 纳克级= 'whatClassIsIt(call.State)'?

1 个答案:

答案 0 :(得分:0)

如果问题不是拼写错误,你必须在控制器中设置'pauseClass'和'muteClass'的值而不是'controlClass'。

scope.doMute = function(){
        var vlc = scope.getVLC("vlc");
         if (vlc && vlc.playlist.isPlaying) {
            vlc.audio.toggleMute();
            scope.muteClass = 'fa fa-volume-off';
        }else{
            scope.muteClass = 'fa fa-volume-on';
        }
}


scope.doPlayOrPause = function(){
        var vlc = scope.getVLC("vlc");
        if(vlc){
            if(vlc.playlist.isPlaying){
                vlc.playlist.togglePause();
                scope.pauseClass = 'fa fa-play';
            }else{
                vlc.playlist.play();
                scope.pauseClass = 'fa fa-pause';
        }
    }
}