0

I am having some weird problem passing multiple parameters using ui-router

My ui-sref looks like this:

ui-sref="app.bins.view({binId:{{gridDisplayItem.id}},allowUpload:'{{gridDisplayItem.user_upload}}'})"

if I inspect the element, I see something like:

<a ui-sref="app.bins.view({binId:3,allowUpload:'No'})" href="#/app/bins/view/3">
  <i class="fa fa-folder-open" style="font-size:18px;color:green"></i>
</a>

so the correct value is being passed.

When I navigate to app.bins.view and I do a console.log($stateParams.binId); it shows 3.

If I do a console.log($stateParams.allowUpload); I get undefined.

If I do a console.log($stateParams); I get Object {binId: "3"}

According to the docs, I am doing this correctly: https://github.com/angular-ui/ui-router/wiki/Quick-Reference#ui-sref

What am I doing wrong here?

9
  • use 'No'...otherwise it is looking for the variable No... Commented Oct 1, 2014 at 18:02
  • I am still getting undefined with quotes around the value. Edited my post to reflect the single quotes Commented Oct 1, 2014 at 18:04
  • did you declare both of your params in your ui-route? Commented Oct 1, 2014 at 18:07
  • remove the href attribute from your link Commented Oct 1, 2014 at 18:07
  • more detailed information about your situation: github.com/angular-ui/ui-router/wiki/… Commented Oct 1, 2014 at 18:08

1 Answer 1

1

Most importantly, the information in the ui-router documentation (https://github.com/angular-ui/ui-router/wiki/URL-Routing#stateparams-service) to understand is the following

$stateProvider.state('contacts.detail', {
   url: '/contacts/:contactId',   
   controller: function($stateParams){
      $stateParams.contactId  //*** Exists! ***//
   }
}).state('contacts.detail.subitem', {
   url: '/item/:itemId', 
   controller: function($stateParams){
      $stateParams.contactId //*** Watch Out! DOESN'T EXIST!! ***//
      $stateParams.itemId //*** Exists! ***//  
   }
})

You must be sure to declare your parameters in the configuration of the provider.

If the purpose of your 'allowUpload' parameter is what I think it is, there should be no reason you cannot use an ng-click event on your href to have a function called in your controller that then uses the $state.go() method to manage the view change. Just pass in the variable to the controller.

Sign up to request clarification or add additional context in comments.

3 Comments

I am defining my controllers in the config like controller: 'ViewBinController' but I understand this and I think using an ng-click coupled with the $state.go will work great, thank you
I'm still trying to get it to work, lol don't worry I won't leave ya hangin
I've got this pattern in lots of places...update your question is you're stuck...

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.