-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);
1

3 Answers 3

0

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

$routeParams.queryParam
Sign up to request clarification or add additional context in comments.

Comments

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

8 Comments

Is it one asterisk or two or four or zero, what is it all about??
did you configure your url parameter name in $routeprovider?
Yes: app.config(function ($routeProvider, $locationProvider) { $routeProvider.when('/Index/:id*', { controller: 'clinicController'}); $locationProvider.html5Mode(true); });
See the controller name is different 'clinicController'. You can get the id param value from 'clinicController' only. You can't it from 'myController'
They are the same actually, I used more generic name in the question
|
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.