How to get parameters from url


#1

Hello.

I’m facing a problem using $urlRouterProvider instead of angular’s $routeProvider.

What I would normally do with $routeProvider is:

 .when('myurl/:param', {
    templateUrl: 'whatever.html',
    controller: MtCtrl'
  })

and then

 .controller('MtCtrl', function ($scope, $routeParams) {
     ...
     console.log($routeParams.param)
   ....

I’m trying that way with $urlRouterProvider:

.state('tabs.home', {
  url: "/home/:param",
  views: {
    'home-tab': {
      templateUrl: "home.html",
      controller: 'HomeTabCtrl'
    }
  }
})

and in the controller

 .controller('HomeTabCtrl', function ($scope, $routeParams) { 
   ...
   console.log($routeParams.param)
   ....

but I’m getting undefined.

Anybody knows how to get that working?

Thank you.


#2

Take a look at this :wink:


#3

Awesome gregorypratt, thank you.


#4

video about ui-router