Hasan Can Saral
Hasan Can Saral

Reputation: 3288

routeParams are Empty

I am trying to get URL parameters using $routeParams:

var myApp = angular.module('myApp', [
  'ngRoute',
  'appControllers',
  'appFilters',
  'appServices'
]).config(['$routeProvider', function($routeProvider) {
  $routeProvider.when('/admin/organisations/:organisation_id', {
    controller: 'UpdateOrganisationCtrl'
  });
}]);

and in my Controller:

appControllers.controller('UpdateOrganisationCtrl', ['$rootScope', '$scope', '$http', '$window', '$routeParams',
function($rootScope, $scope, $http, $window, $routeParams) {

    console.log($routeParams.organisation_id);

}]);

However I am printing undefined as $routeParams is {} Any thoughts?

Upvotes: 2

Views: 194

Answers (1)

Cyril Gandon
Cyril Gandon

Reputation: 17058

The url you tried to access should be

localhost:3000/#/admin/organisations/56cde4bf911747ea200d5a63

ngRoute will make your application a Single Page Application, where the relevant part of the url for the router will be after # (beautifully called the hashbang).

Look at the example:

// Given:
// URL: http://server.com/index.html#/Chapter/1/Section/2?search=moby
// Route: /Chapter/:chapterId/Section/:sectionId
//
// Then
$routeParams ==> {chapterId:'1', sectionId:'2', search:'moby'}

However, the url you give could work if you use HTML5Mode for $location service of angular.

See those links for more information:

Upvotes: 2

Related Questions