JavaScript Keep all states when going back

I have multiple pages in my Angular app that the user can change quite a bit, i.e. open tabs and pills, modals, etc. Let's say, for example, they open a modal and then click a link in that modal which leads them to another page. On that other page, when they go back in their browser history, I'd want them to see the first page the way they left it, i.e. with the modal open, not how it looks when you reload it.

I am using ui-router with Angular 1.4.3.

So far I have looked into the following links:

...but they don't seem to be quite what I need. And I'm not even sure how to google this.

Another example for this is when a user enters something in a search bar, then clicks on a result which leads to a new page. When they go back, they would have to enter the search again, which is not the greatest experience.

Answer:1

Use a service to store page state

Rather than storing page state and user input on the $scope, store it on a persistent service that is injected into the page controller along with the $scope.

Store a reference to the service on the $scope:

myApp.service('MyPageStateService', function() {
    this.someProperty = 'some initial state';
});

myApp.controller('MyPageController', function($scope, MyPageStateService) {
    $scope.state = MyPageStateService;
});

and from the page template access data stored on the persistent state service:

<div ng-controller="MyPageController">
    <p>My page state is {{state.someProperty}}</p>
</div>

When navigating back to this page within the app, the controller will get a new $scope but the same instance of MyPageStateService.

Answer:2

I am generating random numbers and appending with the previous variable and trying to get the value of images. but also the random number only generated. How can I do this ? Here's my code var img1 =...

I am generating random numbers and appending with the previous variable and trying to get the value of images. but also the random number only generated. How can I do this ? Here's my code var img1 =...

  1. generate random image
  2. generate random image python
  3. generate random image javascript
  4. generate random image url
  5. generate random image name php
  6. generate random image matlab
  7. generate random image java
  8. generate random image php
  9. generate random image using base64 string
  10. generate random image online
  11. generate random image numpy
  12. generate random image c#
  13. generate random image linux
  14. generate random image node
  15. opencv generate random image
  16. imagemagick generate random image
  17. generate random background image
  18. opencv generate random image python
  19. swift generate random image
  20. js generate random image

I continuously run into this issue when designing sites that have scroll-based events (animation, parallax, etc etc etc). Is there any reliable to test if a browser halts repainting on scroll, so I ...

I continuously run into this issue when designing sites that have scroll-based events (animation, parallax, etc etc etc). Is there any reliable to test if a browser halts repainting on scroll, so I ...

<ul> <a href="#Project"> <li onclick="project()">Projects</li> </a> </ul> a tab appears and you can click on it, which runs a javascript function ...

<ul> <a href="#Project"> <li onclick="project()">Projects</li> </a> </ul> a tab appears and you can click on it, which runs a javascript function ...

I wish to animate a div to make it appear and slide down with jQuery. I have got my script to work where you hover over an image and another div slides in, should the user leave the mouse hover, the ...

I wish to animate a div to make it appear and slide down with jQuery. I have got my script to work where you hover over an image and another div slides in, should the user leave the mouse hover, the ...