2013-06-06 43 views
0

像這樣:

<div class="item" ng-repeat="priority in priorities" ng-class="{active: {{$index}} == {{routeParams.priorityId - 1}} }"></div> 

<a class="carousel-control left" ng-hide="!goals.length" href="#myCarousel" ng-click="changePriorityIdParam($index)" data-slide="prev">&lsaquo;</a> 

app.controller("PriorityDetailController", function ($http, $scope, $location, $routeParams) { 
    console.log("PriorityDetailController - priorityId: " + $routeParams.priorityId); 
    getPriorityForPriorityId($http, $scope, $routeParams); 

    $scope.changePriorityIdParam = function(index) { 
     console.log("changePriorityIdParam() - index: " + index); 
     $location.path('/priority/' + index); 
     $location.replace(); 
    }; 
}) 
+0

沒有$指標限制只是NG-重複 –

+0

我可以$指數的副本,並得到它的PriorityDetailController不知何故? :/ – Cole

回答

0

不,這沒有任何意義。你想要複製哪個索引,第一個,最後一個,所有這些?你正在爲這個旋轉木馬做一些非常錯誤的事情。

在priorites集合上寫一個過濾器,它將獲得您的活動元素。

或者是這樣的:

$scope.changePriorityIdParam = function() { 
    var index = 0; 
    angular.forEach($scope.priorities, function (priority, idx) { 
     if (priority == routeParams.priorityId - 1) { 
      index = idx; 
     } 
    }); 
    console.log("changePriorityIdParam() - index: " + index); 
    $location.path('/priority/' + index); 
    $location.replace(); 
}; 
+0

我試圖讓我的傳送帶的#item.active匹配當前$ location.path當用戶點擊左或右轉盤按鈕。 – Cole

相關問題