0

I need to convert this line $location.url('/im?p=' + peer);

to using $state, I can't seem to properly get it working. I have followed these stack overflow questions but I can't seem to get it right AngularJs ui-router $location or $state? Angular ui-router - how to access parameters in nested, named view, passed from the parent template?

my app.js has this state currently as this

$stateProvider

.state('home', {
  url: '/home',
  abstract: true,
  templateUrl: 'templates/home/index.html'
})

.state('home.matches', {
  url: '/matches/:p',
  templateUrl: 'templates/home/matches.html',
  controller: 'AppIMController'
})

})

app.js used to be

$routeProvider.when('/im', {templateUrl: templateUrl('im'), controller: 'AppIMController', reloadOnSearch: false});
Community
  • 1
  • 1
  • what's the the name of the html template used with you /im route? – defaultcheckbox Sep 01 '16 at 15:44
  • It's im.html but i renamed it to matches.html in using $state so they are the same but different name if I understand your question correctly – Eduardo Castillo Sep 01 '16 at 15:52
  • You are using query string ``p=' + peer``. So your state would be .state('home.matches', { url: '/matches?p', templateUrl: 'templates/home/matches.html', controller: 'AppIMController' }) – Mohan Singh Sep 01 '16 at 15:53
  • what about the peer variable? I use it to denote a user for example. I don't see it being used in that solution. It's the peer variable in $location.url('/im?p=' + peer); – Eduardo Castillo Sep 01 '16 at 17:08
  • I tried this line `$state.go('home.matches', { url: '/matches?p'+peer, templateUrl: 'templates/home/matches.html', controller: 'AppIMController' }); ` and it still won't work as intended – Eduardo Castillo Sep 01 '16 at 17:12

1 Answers1

0

This should do it for you. You don't need "peer" url property.

state('home.matches', {
      url: '/new?p',
      templateUrl: 'templates/home/matches.html',
      controller: function($scope, $stateParams) {
         $scope.peer = $stateParams.p;
      }
    })
defaultcheckbox
  • 739
  • 2
  • 5
  • 16