angularjs - ui-router navigate to another state onEnter -
i have wizard flow collects informationa
states["wizard"] = { abstract: true, url: "^/wizard", controller: "wizardcontroller", templateurl: "wizard.html" }; states["wizard.input"] = { url: "^/input", views: { "": { controller: "wizardcontroller", templateurl: "form.html" } } } states["wizard.completed"] = { templateurl: "completed.html" };
and wizard flow b that's similar structure that's collecting informationb.
what want when user navigates /wizard, checks if informationb filled, if not, navigate fill informationb first , navigate /wizard continue wizarda.
what's best way redirection when user navigates /wizard , best way return /wizard when wizardb finishes?
for return pass param in url , in wizardb controller check see if needs go wizarda, couldn't quite figure out how first redirect.
thanks in advance.
thanks charlietfl information, use resolve process redirect looks good! here's how end doing:
var redirect = (returnstate: string) => { return ['$q', '$timeout', '$state', 'datamodel', ($q, $timeout, $state, datamodel) => { var deferred = $q.defer(); $timeout(() => { if (datamodel.informationb === "") { $state.go('wizardb.input', { rs: returnstate }); deferred.reject(); } else { // fine, proceed deferred.resolve(); } }); return deferred.promise; } ]; }
and in state config:
resolve: { redirect: redirect("wizarda.input") }
Comments
Post a Comment