5

When passing $stateParams through $state.go it is getting correctly when i click the link directly, but getting null after page refresh or open through another window.

I have the following function:

$scope.urlvalues = function(url,page) {
    var result = {url:url, page:page};
        $state.go("detailpage", result);
}

And my state looks like this:

.state('detailpage', {
            url: "/page/overview",
            templateUrl: "/page_details.html",
            controller: "PageDetailsController",
            params: {
                    url: null,
                    page: null
                    },         
        })

Thanks in advance.

surya s rajan
  • 53
  • 1
  • 4

1 Answers1

5

Can you try:

.state('detailpage', {
        url: "/page/overview/:url/:page",
        templateUrl: "/page_details.html",
        controller: "PageDetailsController",

    })

Then, when you go to the page the url will be set and will be there when you refresh.

Tj Gienger
  • 1,395
  • 1
  • 12
  • 17
  • 1
    What if you don't want to pass the params in the URL? – AlxVallejo Jan 05 '16 at 20:13
  • optional params get a "?" like `/page/overview/:url?/:page?` – Tj Gienger Jan 06 '16 at 03:49
  • 8
    No, I mean what if you need to pass objects as params to certain states. Refreshing the state would lose that state param. Is there a way to maintain the $state.params.myObject without storing it to localStorage for instance? – AlxVallejo Jan 06 '16 at 18:08