search

Home  >  Q&A  >  body text

angular.js - About the problem of angularjs variables being "cached" by the browser

Ask for advice. I use angular on the PC site, which is a course homepage. When I click on the collection, I use angular. The problem is: after clicking on the collection, I click to enter the course to jump to another page, and then click the browser's back button to return to the course homepage. Finally, I found that the collection status was not the result of the operation just now. It seemed that the variables in js were cached. How to solve this?

曾经蜡笔没有小新曾经蜡笔没有小新2823 days ago632

reply all(4)I'll reply

  • 为情所困

    为情所困2017-05-15 17:03:29

    This problem should not occur. According to my idea, the collection status of your page should be controlled by a certain data passed to you by the backend. After you click Collection, send a request to the backend, and then the backend Update that data and return that data to you. As long as this data is updated, won't your collection status be updated? No matter how you enter the page, the collection status should be some data returned to you by the backend, and it will not follow the progress of your browser. There has been a change in going back. I don’t know if my explanation is the same as what you asked

    reply
    0
  • 仅有的幸福

    仅有的幸福2017-05-15 17:03:29

    Can you post the relevant code?

    reply
    0
  • 天蓬老师

    天蓬老师2017-05-15 17:03:29

    First of all, your collection interacts with the server. Secondly, when your page jumps, the controller of the previous page has been destroyed, and there is no variable cache. I think it is necessary for you to retrieve the collected data when the controller is initialized and then display it on the page

    reply
    0
  • 大家讲道理

    大家讲道理2017-05-15 17:03:29

    As long as the URL is changed, the current Controller will be destroyed. When you jump to the interface again by changing the URL, the data in the scope will be initialized data, unless the background sets a value for the object

    reply
    0
  • Cancelreply