define var customers outside getCustomers function (to persist outside runtime function):
app.factory('customersFactory', function(){
var customers = [];
return {
getCustomers: function() {
customers = [
{
id: 1,
joined: '2022-12-02',
name: 'Kanon',
city: 'Mitaka',
orderTotal: 9.9956,
orders: [
{
id: 1,
product: 'Shoes',
total: 9.9956
}
]
},
{
id: 2,
joined: '2012-12-20',
name: 'Takashi',
city: 'Tokyo',
orderTotal: 19.9956,
orders: [
{
id: 2,
product: 'Pants',
total: 19.9956
},
{
id: 3,
product: 'Socks',
total: 0.9956
}
]
},
{
id: 3,
joined: '2000-05-06',
name: 'Kirby',
city: 'Osaka',
orderTotal: 90.9956,
orders: [
{
id: 4,
product: 'Shirts',
total: 90.9956
}
]
}
];
return customers;
},
getCustomer: function(customerId) {
for (var i = 0, len = customers.length; i < len; i++) {
if (customers[i].id === parseInt(customerId)) {
return customers[i];
}
}
return {};
}
}
});