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

Community
  • 1
  • 1
Ahmad
  • 1,462
  • 5
  • 17
  • 40

2 Answers2

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)
Hadi J
  • 16,989
  • 4
  • 36
  • 62
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);
}
Snopzer
  • 1,602
  • 19
  • 31