angularsjs state provider multi params

57 Views Asked by At

I am trying to build state provider that catch multi params but the issue is that i dont know how many params is it possible to catch them as object or array? or the only solution is to catch it as string and separate them?

for example this is my provider

.state('app.confirmPayment', {
        url: '/comfirmPayment/:params',
        templateUrl: '/Views/ConfirmPayment.html'
    })

and controller

app.controller('ConfirmController', ['$scope', '$state', 
    function ($scope, $state) {
        var self = this;

        console.log('$state confirm payment');
        console.log($state);
        console.log('$state confirm payment');

    }
]);

and want to catch all the params separated

/comfirmPayment/:age=15&name=erez.....  // can be more that i dont know

and can be more params that i dont know what they can be

thanks hope its clear

1

There are 1 best solutions below

7
M. Junaid Salaat On

Unless you're binding to the query parameters (see the documentation), you don't access them directly through $state or $stateParams.

Suppose the url

cities?cityId=3&param1=value1

and You can handle this in your router config $stateProvider where you define states

.state('cities', {
          url: "/cities?cityId&param1",
          templateUrl: "cities.html",
          controller: "citiesController"
        })
// will match to url of "/cities?cityId=[any id]&param1=[any value]"

and finally You can have these parameters in the citiesController.js i.e

console.log($stateParams);
//Object {cityId: "3", param1: "value1"}

Hope it helps.