I am using ng-repeat to populate my web page with data fetched from a Rails API.
Within my array, I have 2 objects each with different prices.
The goal is to present the user with a price per hour, but the division factor should vary based on the index of the item in the array. Currently, the code calculates the total price for each item, but I want to divide them differently.
This is the current code:
Javascript/Angular
apiCall(function (data) {
for(var i=0; i<data.length;i++){
controller.holder.push({
id: data[i].id,
price: data[i].price
});
}
controller.holder = [
{
id: 1,
price: 100
},{
id: 1,
price: 500
}]
HTML
<div ng-repeat="pack in Test.holder" class="col-sm-6">
<p>{{pack.hours}} - {{pack.price | currency }}</p>
<button translate>Go</button>
</div>
Desired output should be something like this (refer to comments in the code):
<div ng-repeat="pack in Test.holder" class="col-sm-6">
//if pack index in holder is 0 divide the item by 5
//if pack index in holder is 1 divide the item by 10
<p>{{pack.hours}} - {{pack.price | currency }}</p>
<button translate>Go</button>
</div>
Is there a way to achieve this using $index? Extensive research has not yielded a clear solution.
Your assistance would be highly appreciated. Please feel free to ask for further details if needed.