Whenever a user clicks on a tag in my app, I want to capture the id of the product clicked and store it in an array.
This is how my view looks:
<ion-view view-title='Products'>
<ion-content>
<div class="row">
<div class="col col-25" ng-repeat="row in products">
<a href="#/main/tickets/{{row.productId}}" class="button button-block button-light">{{row.product}}<br/><small>{{row.price | currency}}</small></a>
</div>
</div>
</ion-content>
In the above code snippet, I extract the row.productId of the product. Here's how it's handled in my app.js file:
This is from my app.js:
.state('main.tickets', {
url: '/tickets/:productId',
views: {
'tickets': {
templateUrl: 'templates/tickets.html',
controller: 'ticketsController'
}
}
})
The productId is retrieved as a URL parameter.
Below is my controller function:
.controller('ticketsController', function($scope, $localStorage, $stateParams){
var tickets = [];
tickets.push($stateParams.productId);
console.log(tickets);
})
The tickets array successfully stores the id, but each time a new productId is clicked, the array resets because of the declaration. The goal is to retain all the productId values without resetting the array. Unfortunately, I'm unable to figure out a way to achieve this at the moment.