angularjs - How to wrap route's business logic to forward to other routes? -
I have a UI router path front
my intention is That when the app goes to front , it will use some business logic to redirect to another route: front.register , front.login , Front.loginFirsttime , etc.
This is the first time I go to the route (front -> front.register), but not for the second time.
front - (auto)> front.register - (click) -> front.info - (click ) -> front -! -> front.register
then the controller is not reloaded at all (). Okay, but how do I do this?
Angular Module ('wmw'). Controller ('front', ['$ radius', 'global', 'user', '$ state', function ($ radius, global, user, $ state) {$ scope.Global = Global; $ scope.User = User; console.log ('only play first'); User.loadData (). Then (function (routerstate) {$ state.go ('front.' + RouterState);});}]); User.loadData () prompts a promise when the data has been loaded (then runs). RouterState is the next place to visit. Unfortunately this code is run only once.
In the state of your front , you can see the current state , Because you are monitoring the states of front , you can do it with a simple clock in the front state controller:
angular controller (' Front ', [' $ scope ',' global ',' user ',' $ state ', function ($ scope, global, user, $ state) {$ scope.Global = global; $ scope.User = user; / / Router Save the position. See the current route $ scope.state = $ state; $ scope. $ Watch ('state.current.name', function (v) {// if it runs on every visual change ($ state.current .name === 'front') {User.loadData (). Then (function (routerstate) {$ state.go ('front.' + RouterState);})}}}}}}}); You probably want to be simple, to check if the destination status is not the current state, which is to stop a redirection loop.
Comments
Post a Comment