Reputation: 3041
I've configured a route and try to pass parameters to a controller:
app.js
.config(function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('spot', {
url: "/spot/:param",
templateUrl: "templates/spot.html",
controller: "SpotCtrl"
});
$urlRouterProvider.otherwise('/');
});
controller:
angular.module('spotx.controllers')
.controller('SpotCtrl', ['$scope', '$routeParams',
function($scope, $routeParams) {
$scope.do = function() {
console.log($routeParams.param);
};
}])
The url is /#/spot/1111, but if I fire the do-function I get undefined in the console.
Upvotes: 1
Views: 273
Reputation: 171679
$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
Upvotes: 4