I'm currently developing an App that requires the user to input numbers into two different fields. The first field is for entering numbers, while the second field displays a calculation based on the input. Each time the user enters a number, a call to the database is made, and I'd like to minimize these calls. Ideally, I want to give the user some time to enter the input before making the database call.
Below is the function defined in a service:
applyStraightRisk = function(slip, amount) {
applyStraightRiskWin({
wagerType: '1',
riskOrWin: 'RISK',
riskValue: amount,
winValue: slip.win || 0,
amount: amount,
selections: [slip]
});
}, applyStraightWin = function(slip, amount) {
applyStraightRiskWin({
wagerType: '1',
riskOrWin: 'WIN',
riskValue: slip.risk,
winValue: amount,
amount: amount,
selections: [slip]
});
}
return {
riskWinCalculations: function(params, scope, index) {
switch (params.type) {
case 'RISKSTRAIGHT':
applyStraightRisk(params.slip, params.slip.risk);
break;
case 'WINSTRAIGHT':
applyStraightWin(params.slip, params.slip.win);
break;
};
}
One option I was considering was using $timeout/setTimeout
but I wonder if there is a more effective approach?