rakete rakete - 2 years ago 131
AngularJS Question

$routeParams.param returns undefined

I've configured a route and try to pass parameters to a controller:


.config(function($stateProvider, $urlRouterProvider) {
.state('spot', {
url: "/spot/:param",
templateUrl: "templates/spot.html",
controller: "SpotCtrl"


.controller('SpotCtrl', ['$scope', '$routeParams',
function($scope, $routeParams) {

$scope.do = function() {


The url is /#/spot/1111, but if I fire the do-function I get undefined in the console.

Answer Source

$routeParams is for ngRoute router not angular-ui-router.

You need $stateParams ... see ui router docs

I'm suprised you aren't getting an unknown provider error unless you have both router scripts included in page and have ngRoute also injected in a module

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download