There exist only two methods to persist data throughout all components of an Angular application during the digest cycle.
1--$rootScope (not recommended)
2--utilizing Angular Services
Based on your comment, I assume that when you mention
"I am not using any service to maintain it and I want to maintain it in the angularjs only,"
you are referring to third-party or backend services. Angular provides its own array of services that you can leverage, such as cookies service, storage service, or alternatively, you could create your shipping cart service. My recommendation would be constructing a custom shopping cart service that manages all operations and data tracking. Angular services act as singleton objects for an application, ensuring data persistence. Creating services is pretty straightforward; here's an example:
app.service('myservice',['$rootScope','$http','$timeout',function($rootScope,$http,$timeout){
//$rootscope useful if you want to broadcast events to the app
//$http useful if you want to update based on the users selection or deletion
//$timeout useful if you want to set time-based alerts or expirations
var storage={};
return{
insert:function(item){/*logic to insert an item into storage*/},
remove:function(id){/*logic to remove an item from storage*/},
get:function(id){/*logic to get all items*/}
}
}])
A CONTROLLER IMPLEMENTING THE SERVICE
app.Controller('Category1ItemsController',['myservice',function(myservice){
$scope.items=[1,2,3,4,5,6]
$scope.appendItem=function(item){
myservice.insert(item);
}
}]);
A VIEW UTILIZING THE CONTROLLER
<ul ng-controller="Category1ItemsController">
<li ng-repeat="item in items">
{{item}}
<button ng-click="appendItem(item)">Add</button>
</li>
</ul>
Something along these lines should provide you with more clarity. Which generator/template project are you currently working with?