angularjs - Persistent Array in Angular Factory Possible? -
i'm attempting create persistent array throughout client's session without using $window.sessionstorage. right every single time change route array empties out, if it's same exact route on. possible make data persistent without using sessions or localstorage?
var = [];
pushing it:
a.push(b);
result of after rerouting: [];
your controller function re-run on route changes, clearing local variables every time. there few ways skin cat here, suggest using $rootscope
, special top level controller won't re-run unless whole app refreshes.
// controller function whatevercontroller ($scope, $rootscope) { // create array if 1 doesn't exist yet $rootscope.persistentarray = $rootscope.persistentarray || [] $rootscope.persistentarray.push('heyoo') $scope.localarray = $rootscope.persistentarray }
$rootscope
can passed factories (pretty sure), can achieve want typical factory, scoped variables getter / setters
Comments
Post a Comment