This was solved via using a service rather than a factory as described on the plunker: http://plnkr.co/edit/uh23lrXz2mI4ukvJvxws?p=preview provided by @Incognos. Accepted answer was @Tomislav as he first mentioned using a service.
I've created a controller to handle the stores items, they're stored like such (removed reiterations to save space on here):
'use strict';
angular.module('angularStoreApp')
.controller('storeCtrl', function($scope){
$scope.product = {
items: [
{
qty: 0,
stock: 5,
price: 99.00,
name: 'Almond Toe Court Shoes, Patent Black',
category: 'Womens Footerwear'
}
]
};
});
I need to create a service to hold this data so it can be accessed from another view/controller. (It'll be the final cart page). I've attempted to use .factory, then in the controller $scope.products = serviceName.items; but to no avail. I've injected the service via the controller also. I'm given a $injector:modulerr error.
To clarify, the service I created is this
var app = angular.module("angularStoreApp", []);
app.factory("StoreService", function() {
var products = {
items: [
{
qty: 0
}
]
};
return products;
});
The controller then is as such:
'use strict';
angular.module('angularStoreApp')
.controller('storeCtrl', function($scope, StoreService){
$scope.product = StoreService.items;
});
I'm stuck on how to put my data from the original controller into the service and then inject the service into the controller to display the items once again. To note, NOT using a service, the data is displayed in the view perfectly fine.