Istvan
Istvan

Reputation: 8562

Angular routeParams is undefined

I am trying to use routeParams in my JS but it always passed in as undefined.

app.controller('ShowKey', function($scope, $http, $routeParams, $log) {

  $log.info('SomeCtrl - starting up, yeah!');
  $log.info($routeParams);

  $scope.getKey = function() {
    $log.info($routeParams);
  };
});

Is there anything else what I need to set other than calling the app.controller with routeParams?

Upvotes: 0

Views: 3587

Answers (1)

Milad
Milad

Reputation: 28592

1- Have you consider any routeParams in your config anyway ? 2- if you want to get your routeParams in your config , well , you cant,

---you must use :

$route.current.params , instead

    app.config(function($routeProvider){
      $routeProvider.when('/path/:yourRouteParam'
       templateUrl:"your template url address",
        controller:'your controller',
        resolve: {
            resolbeObject: function($route){
             //**here you cannot use $routeParam to get "yourRouteParam"** property
            // you must use : $route.current.params
            }
        }
    })
    });

But in your controller you can get yourRouteParam with $route.params , just if you have defined route params in your route confige like this :

       $routeProvider.when('/path/:**yourRouteParam**

NOTE if you want to define any route param you must use(:), not (?)

Upvotes: 2

Related Questions