How to execute AngularJS controller function on page load?

前端 未结 14 2314
一整个雨季
一整个雨季 2020-11-22 16:04

Currently I have an Angular.js page that allows searching and displays results. User clicks on a search result, then clicks back button. I want the search results to be disp

相关标签:
14条回答
  • 2020-11-22 16:36

    You can use angular's $window object:

    $window.onload = function(e) {
      //your magic here
    }
    
    0 讨论(0)
  • 2020-11-22 16:37

    You can save the search results in a common service which can use from anywhere and doesn't clear when navigate to another page, and then you can set the search results with the saved data for the click of back button

    function search(searchTerm) {
        // retrieve the data here;
        RetrievedData = CallService();
        CommonFunctionalityService.saveSerachResults(RetrievedData);
    } 
    

    For your backbutton

    function Backbutton() {
        RetrievedData = CommonFunctionalityService.retrieveResults();
    }
    
    0 讨论(0)
提交回复
热议问题