angularjs - How do you access url parameters inside of $stateProvider.state's stateConfig object? -
.state('edit', { url: '/edit/:id', templateurl: 'app/skims/form/form.html', controller: 'formctrl formctrl', authenticate: { loggedin: true, authorized: // :id } })
i'd assign authorized
:id
part of url. there way this?
my reason wanting set authorization.
.run(function ($rootscope, $location, auth) { // redirect login if route requires auth , you're not logged in $rootscope.$on('$statechangestart', function (event, next) { if (typeof next.authenticate !== 'undefined') { auth.isloggedinasync(function(loggedin) { if (next.authenticate.loggedin && !loggedin) { alert('must logged in access route.'); $location.path('/login'); } if ( next.authenticate.authorized && auth.getcurrentuser()._id !== next.authenticate.authorized) { alert('unauthorized. must signed in right user.'); $location.path('/login'); } if (next.authenticate.admin && !auth.isadmin()) { alert('must admin access route.'); $location.path('/login'); } }); } });
particularly
... if ( next.authenticate.authorized && auth.getcurrentuser()._id !== next.authenticate.authorized)
this solved using more prams of $statechangestart
event
// instead of $rootscope.$on('$statechangestart', function (event, next) { // can use $rootscope.$on('$statechangestart' , function (event, tostate, toparams, fromstate, fromparams) {
and means, have access passed params inside of toparams
. can evaluate this:
// instead of // ... // && auth.getcurrentuser()._id !== next.authenticate.authorized. // can use auth.getcurrentuser()._id !== toparams.id
Comments
Post a Comment