Jai Kumar Rajput
Jai Kumar Rajput

Reputation: 4217

set dynamic values to ng-switch-when='1' in AngularJS

I'm new to AngularJS, I'm using

<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>

When I'm using ng-switch-when='1' it is working but, I'm trying to ng-switch-when works dynamic with the index if current loop element.

Please help!

Upvotes: 0

Views: 509

Answers (1)

Suresh B
Suresh B

Reputation: 1652

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>

Upvotes: 1

Related Questions