I have an Angular app used to track hours worked by the user. When the user adds a new job, they are taken through a wizard, with each page/controller adding a new property to the job object. Once the wizard is complete, the user can start tracking by navigating to the jobs home page from the app main page.
It is, however, possible to exit the wizard before it is completed (via the back button) and then navigate to the home page of the job. What I need is for the controller for that home page to redirect to the appropriate wizard page for whichever job property is missing.
The job variable is retrieved from local storage at the start of the controller code.
var job = DatastoreService.objectJob();
job.initFromHash($routeParams.jobHash);
function checkJobProps(prop, route){
if(!job.data.hasOwnProperty(prop))
$location.path('/wizard/add-position/' + $routeParams.jobHash + '/' + route);
}
checkJobProps('taxSettings', 'tax');
checkJobProps('payrollSettings','payroll-opt');
checkJobProps('breaks', 'breaks');
checkJobProps('allowances', 'allowances');
checkJobProps('deductions', 'deductions');
checkJobProps('generalSettings', 'general-settings');
There is code below this on the controller that breaks if certain properties are not available. None of these function calls execute fast enough to prevent errors. They will redirect, but not elegantly and it will also always be the last one in the list that takes effect.
Do I do this with a promise? The navigation that is used from the home page of the app to the home page of each job is a directive so, I guess it may be possible to init the job from the $routeParams.jobhash and check these properties within the directive, but I would have to learn more about directives first.
Any help would be much appreciated.
i have two tabs, one shows some hotel names from one location and other tab shows some hotels from another location. and when i select one hotel from one tab and then another from another tab. the ...
i have two tabs, one shows some hotel names from one location and other tab shows some hotels from another location. and when i select one hotel from one tab and then another from another tab. the ...
Please be nice. My first question here. I'm learning JavaScript and jQuery. Google isn't much help because I don't know how to ask the right question. Need human intervention please. I'm trying to ...
Please be nice. My first question here. I'm learning JavaScript and jQuery. Google isn't much help because I don't know how to ask the right question. Need human intervention please. I'm trying to ...
new Array // outputs [] [] // outputs [] But new Array === [] is false. Why so? console.log(new Array === [])
new Array // outputs [] [] // outputs [] But new Array === [] is false. Why so? console.log(new Array === [])
I've written a function to turn a string such as 'aaazeeeee' into a new string of 'aaa z eeeee' this is the code I've tried that works const groupCharacters = signature => { let ...
I've written a function to turn a string such as 'aaazeeeee' into a new string of 'aaa z eeeee' this is the code I've tried that works const groupCharacters = signature => { let ...