angularjs - Angular Router - Using abstract state to access service -


using mean.js:

i have large application divided say, offices. each office accesses same application in same way, employees of office may access information pertaining office. company administrators may access app fully, switching between office contexts. caveat there no user accounts (no login/auth) office employees, admin accounts administrators.

i'm exploring doing in following way:

i created access module service stores office context, passing backend when making api calls. set upon application startup config files.

this , good, need allow administrators switch office contexts. use link <a ui-sref="context({ officeid: 'x' }) (in navbar dropdown, accessible every state) access angular router:

.state('context', {         url: '/context/:officeid',         controller: 'contextcontroller',         controlleras: 'vm'       }); 

this passes officeid contextcontroller, set contextservice.officeid variable. @ time, believe make api call contextcontroller refresh current state's data reflect current context. not sure how that.

i feel have options here, unsure how implement:

  • i can make context state abstract, , every other state child, seems bulky. if correct, how tell current state refresh it's data?
  • i enter context state, set contextservice.officeid, , redirect previous state, upon entering, should make api call using new context. if correct, how perform redirect?

i scrap how being done entirely, don't know start. advice welcome.

i figured out feels bit more elegant.

i still use context route. i've included contextservice in of angular modules, , call when context needs set. tried redirect using $location.path(...), major headache. using $state.go($state.previous.state.name) works treat.

even better, if use routes depend on resolves, can further redirect using $state.go($state.previous.state.name, $stateparams);


Comments