【问题标题】:set dynamic values to ng-switch-when='1' in AngularJS在 AngularJS 中将动态值设置为 ng-switch-when='1'
【发布时间】:2017-05-31 07:36:58
【问题描述】:

我是AngularJS 的新手,我正在使用

<div class="imageslide" ng-switch='slideshow' ng-animate="'animate'">
   <div ng-repeat="img in images">
      <div class="slider-content"  ng-switch-when='$index'>
          <!-- <p>Slider's are amazing1!</p> -->
          <img ng-src="{{img.image_thumb}}">
      </div>  
   </div>
</div>

当我使用 ng-switch-when='1' 时,它正在工作,但是,我试图 ng-switch-when 在当前循环元素的索引中动态工作。

请帮忙!

【问题讨论】:

标签: angularjs


【解决方案1】:

var app = angular.module("myApp", []);
app.controller("myCtrl", function($scope) {
  $scope.records = [
    "Alfreds Futterkiste",
    "Berglunds snabbköp",
    "Centro comercial Moctezuma",
    "Ernst Handel",
  ]
});
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>

<body ng-app="myApp" ng-controller="myCtrl">

<h1 ng-repeat="x in records">
<div ng-switch="$index">
<span style="color: red" ng-switch-when="1">{{x}}</span>
<span style="color: blue" ng-switch-when="2">{{x}}</span>
<span style="color: green" ng-switch-when="2">{{x}}</span>
</div>
</h1>
 

</body>
</html>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-10-02
    • 1970-01-01
    • 2017-02-23
    • 1970-01-01
    • 2014-06-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多