ng-repeat to show data from database but my order by predicate,reverse functionality and click is not working
<div ng-repeat="shipment in sortedShipments">
<div ng-click="show_shipment($index,shipment.shipment_id)" ng-class="{selected_trip: $index === currentShipment}">
<div>{{shipment.from_location}</div>
</div>
</div>
here is fetching records from database HTTP request and sorting code
$http.get(url+'/get-shipments').success(function(data){
$scope.shipments = data;
$scope.sortedShipments = $filter('orderBy')($scope.shipments, 'predicate', true);
$scope.currentShipment = 0;
$scope.sortType = 'shipment_id';
$scope.predicate = 'created_at';
$scope.reverse = false;
});
for click functionality i have two button to move to next shipment div using selected index and previous button
<a class="" ng-click="next($event)" href="#">next</a>
<a class="" ng-click="previous($event)" href="#">previous</a>
and angular js code is
$scope.next = function($event) {
if ($scope.currentShipment < $scope.sortedShipments.length - 1) {
$scope.currentShipment++;
$('.selected_trip').click();
}
};
$scope.previous = function($event) {
if ($scope.currentShipment > 0) {
$scope.currentShipment--;
$('.selected_trip').click();
}
};
the problem is it goes to next item add selected_trip class on it but i also want to trigger a click on selected class so that it can call this function on the selected row ng-click="show_shipment($index,shipment.shipment_id)"
but currently $('.selected_trip').click(); this is giving me error
i have also tried this to
document.querySelector('.selected_trip').click();
here is show_shipment method
$scope.show_shipment = function(index,id) {
$scope.setSelected(index);
$http.get(url+'/get-shipments/'+id).success(function(data){
$scope.to_location = data[0]['to_location'];
})
})
Here is my code for order by which is not working when i started to use the $filter option in js
$scope.order = function(predicate) {
$scope.reverse = ($scope.predicate === predicate) ? !$scope.reverse : false;
$scope.predicate = predicate;
};
$('.selected_trip').click();. This will not guarantied to work, as well asdocument.querySelector('.selected_trip').click();.