Angular LocalStorage
<p>Hi guys i am trying to save some information with localStorage in angular, i injected $window to my service and i created a factory call $localStorage</p>

<pre><code>.factory('$localStorage', ['$window', function($window) {
        return {
            store: function(key, value) {
            $window.localStorage[key] = value;
            },
            get: function(key, defaultValue) {
            return $window.localStorage[key] || defaultValue;
            },
            storeObject: function(key, value) {
            $window.localStorage[key] = JSON.stringify(value);
            },
            getObject: function(key,defaultValue) {
            return JSON.parse($window.localStorage[key] ||     defaultValue);
            }
        }
        }])
</code></pre>

<p>i have other factory where i make us of the localStorage factory in order to save some favorites</p>

<pre><code>factory("favoriteFactory", ["$resource", "baseURL", "$localStorage", function($resource, baseURL, $localStorage) {
        var favFac = {};
        var favorites = $localStorage.getObject("favorites", "[]");

        favFac.addToFavorites = function(index) {
            for (var i = 0; i &lt; favorites.length; i++) {
                if (favorites[i].id == index)
                    return;
            }

            $localStorage.storeObject("favorites", {id: index});
            //favorites.push({id: index});
        };

        favFac.deleteFromFavorites = function (index) {
            for (var i = 0; i &lt; favorites.length; i++) {
                if (favorites[i].id == index) {
                    favorites.splice(i, 1);
                }
            }
        }

        favFac.getFavorites = function () {
            return favorites;
        };

        return favFac;
    }])
</code></pre>

<p>the problem is when i add a favorite item, it replaces itself in my array, instead of adding a new one to the array,</p>

<p>i really aprecciate the help
thanks in advance</p>