Hi Shridar,
First of all, do yourself a favour and read through the styleguide
<https://github.com/johnpapa/angular-styleguide>. twice! Try avoid using
$scope, you really don't need it. Your future self will thank you ;)
Second, the way you set it up, is not how promises work. they are async,
you can't assign a promise to a variable, and then expect the result in
there. it will be the promise that's in there.
I redid your code a bit, I'm not sure it works, that's the reason we ask to
provide a working plunk, so we can help you better.
mainApp.controller('MainCtrl',
['$scope', 'AngularService', '$q', 'MainService',
function ($scope, AngularService, $q, MainService) {
$scope.tempArray = ["Draft", "Draft", "RequestApproval", "Issue", "Approve",
"RequestApproval", "Approve", "Draft", "Issue", "Approve", "Draft",
"RequestApproval", "Issue"];
$scope.name = "Sridhar Babu";
$scope.statusArray = ["", "Draft", "RequestApproval", "Approve", "Issue"];
$scope.Map = [];
$scope.UpdatedResult = "Fail";
$scope.ResultArray = ["Str1", "Str2", "Str3"];
var chain = $q.when();
$scope.booleanValue = false;
$scope.ValidationCheck = function () {
angular.forEach($scope.ResultArray, function (item) {
getConfirmationPopupForConfirmAndComment(item, "action")
.then(res => {
console.log(res);
});
}
};
var getConfirmationPopupForConfirmAndComment = function (message, action) {
retutn AngularService.ConfirmAndAct(item, action)
}
}]);
//AngularService.js
mainApp.service('AngularService', ['$http', '$q', function ($http, $q) {
this.GetHTTPFunction = function (message) {
var url = '/api/List?str=' + message;
return $http.get(url);
}
this.ConfirmAndAct = function (message, action) {
return this.GetHTTPFunction(message)
.then(successCallback)
.catch(errorCallback);
function successCallback(response) {
console.log("Success");
console.log(response);
return response.data;
};
function errorCallback(error) {
console.log("Error in Getting Data");
};
};
}]);
Hope this helps you a tad,
Regards
Sander
--
You received this message because you are subscribed to the Google Groups
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.