I have a function called itemService.. gets item from shoppingList controller and push it into items array then return this array back.
now i need to create 2 shoppingLists so using .factory i manged to make both controllers get different version of the service doing this code when i push an item through first controller the array for second controller won't get this item they are spattered now how can i do the same using .provider
function itemService (limit){
let share = this;
share.items=[];
share.additem=function(N,Q){
if(limit===undefined || limit>=share.items.length+1){
let item={N,Q};
share.items.push(item);
}
else {
throw new Error("limit reached !")
}
}
share.getItems=function(){
return share.items;
}
}
function itemServiceFactory(){
let factory = function(limit){
return new itemService (limit);
};
return factory;
}