In all of my controllers I notice I have the same code over and over again after posting data. See below. Is there someway I can just pass my service to some sort of common function and handle everything there.
//user submits via click
$scope.submit = function(val) {
MyService.update(val).then(function(result) {
if (result.Success) {
$state.reload();
}
else {
$state.go('^');
}
})
}
Maybe turn this into just
$scope.submit = commonFn(MyService.update(val));
Any advice on the best way to avoid this redundant code would be great!