I have method in angular controller which call service; this method should act based on the service response.
but I don't know why the method call in the right time.
$scope.UpdateSelected = function () {
$rootScope.showConfirmModal().result.then(function () {
var selectedItems = _.filter($scope.Options, { Selected: true });
var error = 0
for (var i = 0 ; i < selectedItems.length; i++) {
InvalidOptionsFactory.UpdateOptions(selectedItems[i].Id).then(function (res) {
if (res.data.error) {
error++;
}
});
}
if (error == 0) {
toastr.success($rootScope.GetString('GENERIC_SAVE_SUCCSS_MSG'));
}
else if (error == selectedItems.length) {
$rootScope.showMessageModal($rootScope.GetString('UPDATE_STATUS_FAILED'), 'sm');
}
else {
var message = hasError + $rootScope.GetString('UPDATE_STATUS_PARTIALLY_FAILED');
toastr.success(message);
}
fetchSearchedData();
});
};
I don't now why it's directly go to if statement and execute it then call the service