Using arrays and services


#1

Community’m saving in an array using a json service list. This should be kept only as long as the application is running why not occupy database. Save the data as the application works I works perfect except for one small detail, for example, if I have 2 saved data, I browse the app and come back to save other data. Replaces existing and leaves only 1 data. I return to the example of having saved data, if I sail and I will see my list of stored data is maintained both, but to add new one above is lost. I have, by default, a maximum of 3 data. Dejare images and part of my code. If someone could tell me some other more effective way to do this, they are appreciate.

I wanted before saving a record, if you ask me my service returns empty but it did not work I came.

Service :

.service('misCorredoresService',function(){
  var corredores ={};
      return {
         getCorredores:function(){
         return corredores;
      },
     setCorredores:function(data){
        corredores = data;
      }
   }
})

Function :

$scope.mis_corredores = [];
if($scope.mis_corredores.length <=2){
      $scope.mis_corredores.push(data.list[0]);
      misCorredoresService.setCorredores($scope.mis_corredores);
}

#2

Rewrite your service like this:

.service('misCorredoresService',function(){
  var _model ={};

      return {
         getCorredores:function(){
            return _model.corredores;
         },
         setCorredores:function(data){
           _model.corredores = data;
         }
      }
})