0

I am using the $routeParams service. when i console_log($routeParams) the service in my controller i see in the console all the values.

However when i console log $routeParams.id i get undefined. ( when i console out $routeParams i see the parameters )

i am able to get the values only if i use timeout:

$timeout(function() {
    $scope.id = $routeParams.id;
}, 100);

any idea why that happens? its really weird and i think i am missing something.

Aryeh Armon
  • 2,137
  • 2
  • 22
  • 37
  • can you post sample fiddler for the same. – NiRUS Dec 15 '15 at 10:23
  • 2
    Possible duplicate of http://stackoverflow.com/questions/17519937/routeparams-is-empty-in-main-controller, the top answer provides a solution to this problem. – leroydev Dec 15 '15 at 10:23

1 Answers1

1

I found an alternative way:

$scope.$on('$routeChangeSuccess', function() {
    // $routeParams.id exists
});  
Aryeh Armon
  • 2,137
  • 2
  • 22
  • 37