georoot
georoot

Reputation: 3617

Issue while getting routeParams in angularjs?

I have two separate controllers on same page which need a GET param from the url. The following is my template

  body(ng-app='application')
    .loader(ng-controller="loaderCtrl" data-ng-class="{'hidden': counter == 0}")
      #bar
    div(ng-include="'/components/nav/nav.html'")
    div(ng-view)
    div(ng-include="'/components/footer/footer.html'")
    script(src='app.js')
    script(src='//localhost:35729/livereload.js')

The first controller is for nav and the other is for the template from ng-view.

I am able to get the parameters properly inside ng-view controller but the same is not working in navController. Both the controllers have a simple script as

module.exports = function($scope,Restangular,$localStorage,$routeParams){
  console.log($routeParams);
}

The result that i get in both cases for same page is different. The results being

Object {  }  app.js:576:5
Object { q: "test" }  app.js:383:3

The empty being from controller from nav template and the other being from ng-view. Where am i going wrong here ?

Upvotes: 0

Views: 29

Answers (1)

Matej Marconak
Matej Marconak

Reputation: 1413

Check ngRoute documentation. Try use $route.current.params, because when controller is inicializing $routeParams are empty.

Upvotes: 1

Related Questions