I'm developing an app using Ionic Framework (Angular+Cordova).
The app have a News section with a list of news loaded from a server in JSON, then I tap in a new to open the Single New's View, but when go back to the list of news, $scope has been cleared and must get again the news list from the server.
Is this the usual behavior or am I doing something wrong?
How could I prevent this behavior?
Thanks!
You can also use
$rootScope
. As Onosa mentioned in the comments, every time you instantiate a new controller a new$scope
variable is injected in, but the$rootScope
(as the name says) keeps preserved for the whole life of your app (it's global).You should save this kind of data in a separate service, something in the line of this: