Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/459.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在ng-repeat中实现ng风格_Javascript_Css_Angularjs_Html - Fatal编程技术网

Javascript 在ng-repeat中实现ng风格

Javascript 在ng-repeat中实现ng风格,javascript,css,angularjs,html,Javascript,Css,Angularjs,Html,我在ng repeat中使用了ng样式。ng样式将引用我在控制器中创建的条件。 下面是我的html代码片段: <a class="item item-icon-left dark" ng-repeat="number in numbers"> <span class="badge badge-balanced" ng-style="{'background' : bgColor}">{{number.status}}</span>

我在ng repeat中使用了ng样式。ng样式将引用我在控制器中创建的条件。 下面是我的html代码片段:

    <a class="item item-icon-left dark" ng-repeat="number in numbers">
      <span class="badge badge-balanced" ng-style="{'background' : bgColor}">{{number.status}}</span>
    </a>

{{number.status}
下面是我的js代码片段:

.controller('Ctrl', function($rootScope) {

  $rootScope.numbers = [];
  $rootScope.bgColor = [];
  for(var i=1;i<=amt;i++)
  {
      var ticlist = JSON.parse(localStorage.getItem('storage' + i));
      $rootScope.numbers.push(ticlist);

      if (ticlist.status == "s1")
          $rootScope.bgColor[i-1] = "blue";
      else if (ticlist.status == "s2")
          $rootScope.bgColor[i-1] = "red";
      else if (ticlist.status == "s3")
          $rootScope.bgColor[i-1] = "green";
  }
)};
.controller('Ctrl',函数($rootScope){
$rootScope.numbers=[];
$rootScope.bgColor=[];

对于(var i=1;i有很多方法可以解决这个问题,但是这个呢

CSS:

HTML:


{{number.status}

有很多方法可以解决这个问题,但是这个呢

CSS:

HTML:


{{number.status}

为什么要使用$rootScope?除了使用$scope而不是$rootScope外,您还可以将bgColor属性添加到相应的数字中,以便在ngStyle中执行number.bgColor或添加bgColor[$index]对于您当前的ng样式,numbers属性是我从本地存储中获取的项目。它将被推送到ticlist,其中一个数据是我获取ticlist.status的位置。为什么要使用$rootScope?除了使用$scope而不是$rootScope外,您还可以将bgColor属性添加到相应的数字中,以便您可以在ngStyle或ad中执行number.bgColorbgColor[$index]对于您当前的ng样式,numbers属性是我从本地存储中获取的项目。它将被推送到ticlist,其中一个数据是我获取ticlist.status的位置。为什么要使用$rootScope?除了使用$scope而不是$rootScope外,您还可以将bgColor属性添加到相应的数字中,以便您可以在ngStyle或ad中执行number.bgColord bgColor[$index]到您当前的ng样式数字属性是我从本地存储中获取的项目。它将被推送到ticlist,其中一个数据是我获取ticlist.status.Thank的地方。但是有使用js的答案吗?谢谢。但是有使用js的答案吗?谢谢。但是有使用js的答案吗?
.s1 {
    background-color: red;
}
.s2 {
    background-color: green;
}
.s3 {
    background-color: blue;
}
<a class="item item-icon-left dark" ng-repeat="number in numbers">
    <span class="badge badge-balanced {{number.status}}">{{number.status}}</span>
</a>