将动态值绑定到 ng-repeat(ng-repeat)内的进度条

Bind dynamic values to progress bar inside ng-repeat

本文关键字:ng-repeat 动态 绑定      更新时间:2023-09-26

>我在ng-repeat中有一个角度进度条

<div ng-repeat="item in result">
   <progressbar  animate="false" value="item.status" type="success"><b>{{item.status}}%</b></progressbar></div>

但是我得到的结果变量为

 $scope.result=[
    {
        id: 0,
        name: "Abc",
        status: "InProgress"
    },
    {
        id: 0,
        name: "Abc",
        status: "InHold"
    }
]

如何根据我的 JSON 数据(状态)为进度条内的变量"值"分配特定数字。即,如果状态为"正在进行"值可以为 30。只是我想根据状态有条件地value

任何帮助将不胜感激。谢谢

您可以再编写一个函数,该函数根据状态返回value

喜欢这个

.HTML

<div ng-repeat="item in result">
   <progressbar  animate="false" value="getStatusValue(item.status)" type="success"><b>{{item.status}}%</b></progressbar></div>

.JS

$scope.result=[
    {
        id: 0,
        name: "Abc",
        status: "InProgress"
    },
    {
        id: 0,
        name: "Abc",
        status: "InHold"
    }
]
$scope.getStatusValue(st) {
     if(st == "InProgress") {
          return 30;
     }
     else if(st == "InHold") {
          return 10;
     }
}

它会起作用。