javascript - 如何根据值更改进度条颜色?

标签 javascript angularjs twitter-bootstrap

我正在使用 Angular 和 Bootstrap 制作进度条。目前它工作正常,它可以正确显示进度值。现在我希望我的进度栏使用 types="" ,具体取决于我称为进度的属性的值。我尝试实现 UI Bootstrap 和其他一些堆栈溢出示例中的代码,但我遗漏了一些东西。

有人可以帮忙吗?感谢您抽出时间。

脚本.js

table.controller('workingPlan', function ($scope, $localStorage) {
    $scope.$storage = $localStorage.$default({
        "todos":[
            { "text":"starting work",  "progress":10},
            { "text":"middle of work","progress":50},
            { "text":"lunch brake", "progress":70},
            { "text":"finished working", "progress":100}
        ]   
    });

      $scope.changeType = function(todo) {
        var type;
        if (todo.progress < 30) {
          type = 'success';
        } else if (todo.progress < 60) {
          type = 'info';
        } else if (todo.progress < 90) {
          type = 'warning';
        } else {
          type = 'danger';
        }

        $scope.type = type;
      };

index.html

<tr ng-repeat="todo in plan>     
    <td><progressbar animate="false" value="todo.progress" type="{{todo.type}}"><b>{{todo.progress}}% </b></progressbar></t
</tr>

最佳答案

使用 ng 类 //编辑计划中缺少的“after”todo >

  <tr ng-repeat="todo in plan">     
     <td><progressbar animate="false" value="todo.progress" type="{{todo.type}}" 
     ng-class="{ 'progress-bar-success' : todo.type == 'succes' , 'progress-bar-info': todo.type == 'info', 'progress-bar-warning' : todo.type == 'warning' , 'progress-bar-danger': todo.type == 'danger'}"   >  
     <b>{{todo.progress}}% </b></progressbar></t
 </tr>

关于javascript - 如何根据值更改进度条颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34396468/

相关文章:

javascript - 模态打印输出的变化

jquery - 带有数据表的 Bootstrap 未正确堆叠

html - 如何居中模型内容

javascript - 当只有文件夹路径已知时,使用 javascript/jquery 从 url 获取当前文件名

javascript - 拖动任何devexpress组件时如何防止其他元素突出显示?

javascript - getRowHeight() 不适用于 rowModelType = 'infinite' 和最新的 ag-grid 版本

javascript - 我的插件中的 Successcallback 和 Errorcallback

javascript - 如果用户选择输入文本并且输入值为空字符串,我可以保留占位符吗?

javascript - 使用 Vue.js 从文本输入中按回车键时防止提交表单

javascript - ngRepeat 在 colorbox 中不起作用