nemo_87 nemo_87 - 1 month ago 8
AngularJS Question

Get URL parameters using AngularJs

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?

Answer

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"
            })
    })
Comments