Yes.  Use a service.  If it's not working for you then you are coding it 
wrong.  My guess is not understanding object inheritance and losing a 
reference to primitive values

My examples are not full blown, but hopefully the details will help you see 
what you need:

function EmailService(){
  var emailObject = {
    emails: [],
    currentView: 'inbox',
    folders: []
  }

  return {
     emails: emailObject.emails,
     setCurrentView: function(view){
       emailObject.currentView = view;
    },
    folders: emailObject.folders
  }
  
}

function InboxCtrl($scope, MyService){ 
   $scope.emails = MyService.emails; 
   
   //now whatever you do on the scope will reflect in the service emails 
and will remain there when reloaded
   $scope.emails.push({'from': 'bob', message: 'Hi Larry!'});

   $scope.folders = MyService.folders; 

  $scope.userClickedFolder(folder){
    MyService.setCurrentView(folder)
  }
}

function OtherCtrl(){

}

On Monday, February 10, 2014 8:40:31 AM UTC-7, Yonatan Kra wrote:
>
> I have a SPA (single page app). I am trying to keep data of one route, 
> when moving to another, so if a person returns to the route, he'll see it 
> in exactly the same state he left it.
>
> In example, I have an inbox page (e.g. #/inbox).
> On this page, a person can see his inbox, and gets new messages to the 
> inbox when he stays on this page.  Unread emails are in bold, read emails 
> are normal and they are sorted and filtered in a certain manner the user 
> has chosen. 
> The app gets one "push" of emails from the server, and then updates when 
> it runs.
> It works fine.
>
> The problem arises when this person "navigates" away from the inbox "page".
> The navigation is from #/inbox to #/other-page - each has its own 
> controller and view.
>
> After the person navigates away, and then comes back to the page, the page 
> resets - e.g. the inbox starts from scratch, there are no unread emails in 
> bold, filters are reset etc.
> I followed instructions given me here, to keep the data in a service, but 
> when I get back to #/inbox, the service resets and I lost the data.
>
> How do I keep such data, so the person would see the same inbox page after 
> navigating the rest of the SPA? 
> Or is there a smarter way than just rebuilding the page with saved data?
>
> Thanks
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to