1

I am working on Angularjs, I am stuck in weired problem, I am not able to get parameters value from URL using $routeParams..

var MyApp = angular.module('testAngularApp', ['ngRoute','ngResource'])
    .config(['$routeProvider',
        function ($routeProvider) {
            $routeProvider.
                when('/', {
                when('/updateUser/:id', {
                    templateUrl: 'Pages/User/Edit.html',
                    controller: 'UpdateUserCtrl'
                })
        }]);

controller

angular.module('testAngularApp').
    controller('UpdateUserCtrl', ['$scope', 'updateUserService', '$http','$route', '$routeParams', function ($scope, updateUserService, $routeParams,$route, $http) {
        $scope.testV = "Update User Ctrl";
        console.log("hello");
        $scope.params1 = $routeParams.id; 
        console.log($routeParams.id ); //i am getting undefined
        console.log($scope.params1); //i am getting undefined
        var check = $routeParams['id'];
        console.log(check); //i am getting undefined
    }]);

please tell me how to get values from URL, I have went through these solutions but it didn't work for me.. link1 link2

2 Answers 2

4

I think order of services is wrong. try change as below

controller('UpdateUserCtrl', ['$scope', 'updateUserService','$route','$http' '$routeParams',
                     function ($scope, updateUserService,$route, $http, $routeParams)
Sign up to request clarification or add additional context in comments.

Comments

1
$routeParams

will get the list of parameters from URL to your controller

The function definition is wrong which you defined. its should be defined with the same order as we create for local variables.

controller('UpdateUserCtrl', 
['$scope', 'updateUserService', '$http','$route','$routeParams', 
function ($scope, updateUserService, $http,$route,$routeParams ) {
// your Script goes Here.
console.log($routeParams.id);
}

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.