Issue
I have 2 ng-repeat, and on selecting the inner index, the outer index should highlight. I need to add a colour to a highlighted values and I am using multiple values (i.e., an array of values).
On clicking inner ng-repeat I am trying to push the value to the scope,
$scope.setData = function(isSelected) {
$scope.isSelected.push(isSelected);
console.log(isSelected + " " + $scope.isSelected);
}
<div class="row>"
<div ng-repeat="out in outs track by $index" >
<a href=""
ng-class="getClass($index)">{{out.label}}</a></div></div>
<!-- </div> -->
</div>
<div ng-repeat="out in outs track by $index">
<div ng-if="out_index== $index">
<div>{{out.label}}</div>
<div class="col-md-8">
<!-- <div class="jumbotron vcenter"> -->
<ul class="list-group" ng-repeat="inner in out.inners | orderBy: 'id' " >
<li class="list-group-item cursorPointer">
<img src="{{inner.location}}" alt="{{inner.description}}" title="{{inner.description}}" ng-dblclick="setData($parent.$index)"/>
<div>
<font>{{inner.description}}</font>
</div>
</li>
</ul>
</div>
<!-- </div> -->
</div>
</div>
$scope.isSelected = [];
$scope.getClass = function(ind) {
for(var i=0; i<$scope.isSelected.length; i++) {
console.log("Length " + $scope.isSelected.length + " Scope >>" + $scope.isSelected[i] + " Index " + ind);
if($scope.isSelected[i] == ind) {
return "selected";
}
else {
return "";
}
}
}
Solution
if ($scope.isSelected.indexOf(ind) !== -1) {
return "selected";
}
else {
return "";
}
It works for me.
Answered By - user3428736
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.