-3

I want to take the last value in this url: http://localhost:60954/Home/Index/3

I made this angular app but the object is always undefined

var app = angular.module('myApp', ['ngRoute']);
app.controller('myController', function ($scope, $routeParams) {
    console.log("in ctrlr");
    console.log("parameter");
    console.log($routeParams);
//this always doesn't work. Should I define `id` somewhere?

    console.log($routeParams.id);
mshwf
  • 7,009
  • 12
  • 59
  • 133
  • 1
    Possible duplicate of [AngularJS get current URL parameters](http://stackoverflow.com/questions/20655877/angularjs-get-current-url-parameters) – Aravind Jan 05 '17 at 11:34

3 Answers3

0

You're already injecting $routeParams into your controller. You just have to use it as well.

$routeParams.queryParam
Aer0
  • 3,792
  • 17
  • 33
0

$routeProvider.when('/index/**:id'**, { controller: 'HomeCtrl' });

Where are :id is the param name.So, You should call the param name with the $routeParams like as $routeParams.id

Ramesh Rajendran
  • 37,412
  • 45
  • 153
  • 234
0

I was missing adding ng-view attribute to the container element.

mshwf
  • 7,009
  • 12
  • 59
  • 133