0

I am working with Angular JS (1.x) in which I have one html page (find.html) which has submit button.

When user click on submit button, it performs some search query then it redirects to another html page (result.html) which should display the result of search query.

Both files share the same controller. But when user move to result.html, he can't see the final result as $scope gets die.

how to resolve this issue?

Edit: I used a shared service between two pages. Below is my service code:

app.factory("getSharedDataService",function(){
    var resultData = {};
    function setResultData(obj){
        resultData.status = obj.status;
        resultData.planet_name = obj.planet_names;

    }
    function getResultData(){
        return resultData;
    }

    return { getResultData: getResultData,
             setResultData: setResultData };

});

I used my controller to set the value of resultData when the scope is in first page. But when I try to fetch the value of resultData after reaching to result.html, it comes undefined..

Anubha Gupta
  • 189
  • 2
  • 17
  • You can share it by changing your variable from **$scope** to **$rootScope** in controller which is easy way to solve your problem. – Immanuel Kirubaharan Jan 18 '18 at 08:47
  • Better approach to save _result of search query_ in shared service, which can be used at `result.html` to fetch desired data. – Slava Utesinov Jan 18 '18 at 09:05
  • @SlavaUtesinov I have tried with that approach but its not working. I edited my question and added the code. Could you please tell where I am going wrong? – Anubha Gupta Jan 18 '18 at 09:54
  • @Sajeetharan : Please dont mark my question as duplicate. I have tried the very same approach for solving my problem but its not working. I have edited my question and added the code.. – Anubha Gupta Jan 18 '18 at 09:56
  • @AnubhaGupta, may be it caused by fact, that you perform redirect not via `$state.go('result')` but via `window.location`, so **whole** application is reloaded and service too, i.e. `resultData` is empty. – Slava Utesinov Jan 18 '18 at 10:38

0 Answers0