How to get parameters from url

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.

Take a look at this :wink:

4 Likes

Awesome gregorypratt, thank you.

video about ui-router