What I'm trying to achieve:
Change state when the user clicks previous or next, each state is assigned an id and will need to figure out which id is previous or next before changing previous or next state.
Current Problem:
I have managed to display the current state id '1' and I have managed to group all the other id's within an array but I don't know how to get the next and previous buttons to trigger the right previous or next states on click.
Please find my code below, I've added comments/notes to point things out.
Any help/advice would be helpful!
Thank you.
Controller JS
// -- Current Page ID, '1' -- //
var currentID = $stateParams.id;
// -- Body Type, 'triangle' -- //
var bodyType = $scope.$storage.userData.bodyType.bodyType;
// -- Dress Array, [{"id": "1", "bodyType": "triangle"},{"id": "2", "bodyType": "triangle"},{"id": "3", "bodyType": "round"},{"id": "4", "bodyType": "triangle"}] --//
var dressArray = $scope.$storage.appData.dresses;
// -- Remove anything that doesn't match the current body Type e.g Remove 'round' -- //
var removeRound = $filter('filter')(dressArray, function(value, index) {return value.bodyType == bodyType;});
// -- Dress Array -- //
$scope.dressArray = [];
// -- Push each filter value to Array, ["1", "2", "4"] -- //
angular.forEach(removeRound, function(value, key) {
$scope.dressArray.push(value.id);
});
// -- Console Test, ["1", "2", "4"] -- //
console.log($scope.dressArray);
// -- If currentID = '1', The next button should display '2' -- //
// -- If currentID = '2', The next button should display '4'--//
$scope.nextDress = function() {
$state.go('main.rail', {id: idhere });
};
// -- If currentID = '1', The previous button should display '4' -- //
// -- If currentID = '2', The previous button should display '1' -- //
$scope.previousDress = function() {
$state.go('main.rail', {id: idhere });
};
HTML
<li class="next"><md-button ng-click="nextDress()">Next</md-button></li>
<li class="previous"><md-button ng-click="previousDress()">Previous</md-button></li>