0

got some question for you guys. How can i retrieve data passed as parameter and use it as object/string in my resolve so i can pass it to my controller.

here is my code(not working)

var thisState  =   {
                   name: 'category',
                   url: '/category/:category',
                   templateUrl: 'resources/templates/views/category.html',
                   resolve: {
                      category: function(params) {
                        return params.category;             
                      }
                   },
                   controller: 'CategoryCtrl'
                }

 $stateProvider
 .state(thisState);

this is how i pass param

ui-sref="category({category:'food'})

thanks in advance

cute_programmer
  • 332
  • 3
  • 13

1 Answers1

2

You need to use $stateParams with ui-router

var thisState  =   {
                   name: 'category'
                   url: '/category/:category',
                   templateUrl: 'resources/templates/views/category.html',
                   resolve: {
                      category: ['$stateParams', function($stateParams){
                          return $stateParams.category;
                      }]
                   },
                   controller: 'CategoryCtrl'
                }

 $stateProvider
 .state(thisState);
Hey24sheep
  • 1,172
  • 6
  • 16
  • @arnoldemzi Thanks and You are welcome, don't forget to accept it as answer to close your question. Have a good day :) – Hey24sheep Jan 29 '18 at 05:45