0

I am using states to go from page to page. From one of URLs I am reading parameter from URL (id) and I can easily do this when defining state.

.config(function($stateProvider) {
        $stateProvider
            .state("testing", {
                url: "/testSession/:id",
                controller: "UserTestSessionController",
                templateUrl: "./app/components/userTestSession/user-test-session.html",
                controllerAs: "vm"
            })
    })

My URL looked like this: localhost:8000\testSession\id

If I change URL to look like this: localhost:8000\testSession\id?otp="someStringValue" can I somehow define otp in url param of state? Or do I need to change it totally?

2
  • Do you need otp to be in URL ? can't you use $location to get the query string ? Commented Oct 21, 2016 at 7:11
  • @sajan Well it would be easier to define it in URL if it's even possible. If not I can always use $location, I agree on that. Just wanted to check is there a way :) Commented Oct 21, 2016 at 7:13

1 Answer 1

2

You can just add ?opt to the url

If you need to have more than one, separate them with an '&'

.config(function($stateProvider) {
        $stateProvider
            .state("testing", {
                url: "/testSession/:id?otp",
                controller: "UserTestSessionController",
                templateUrl: "./app/components/userTestSession/user-test-session.html",
                controllerAs: "vm"
            })
    })
Sign up to request clarification or add additional context in comments.

5 Comments

Just one more question. How will I get otp later from Controller for example? Do I use $location, or there is a better way to do it. Because for now I get that ID=1&OTPVALUE. @Weedoze
Use $stateParam.opt
I did, but it's get Id=1&otpvalue and otp = undefine. Let me update my question and add code from Controller. Maybe you will see where is the mistake... @Weedoze
You should ask another question. Your first question was answered. Try to find yourself the solution, if you cannot find come back with another question
I just asked new question. Thanks :) @Weedoze

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.