javascript - URL Route Parameters in AngularJS ui-router -
i want able reload nested view of application , attached route parameter on can have url routing in application. cannot figure out how this, had working query this:
$location.search('userid', user._id); //http://localhost:9000/#/user/?userid=123456789
my desired url below, userid = 123456789
http://localhost:9000/#/user/123456789
my app.js file
$stateprovider .state('index', { url: '/', views: { '@' : { templateurl: 'views/layout.html' }, 'top@index' : { templateurl: 'views/top.html', controller: function($scope, $state) { $scope.userlogout = function() { $state.go('login'); }; } }, 'left@index' : { templateurl: 'views/left.html' }, 'main@index' : { templateurl: 'views/main.html' } } }) .state('index.user', { url: 'user:userid', templateurl: 'views/user/user.html', controller: 'userctrl' }) .state('index.user.detail', { url: '/', views: { 'detail@index' : { templateurl: 'views/user/details.html', controller: 'detailctrl' } } })
in controller:
$state.reload('index.user.detail', {userid: $scope.user._id});
as using ui-router
can use $state.go('index.user', { userid: {{yourid}} });
to allow query string parameter work using ui-router
write state this,
.state('index.user', { url: 'user/?userid=:param', templateurl: 'views/user/user.html', controller: 'userctrl' })
that allow work,
without query string parameter (your desired url) this,
.state('index.user', { url: 'user/:userid', templateurl: 'views/user/user.html', controller: 'userctrl' })
Comments
Post a Comment