Reputation: 13616
I created this http service:
(function () {
"use strict";
angular.module("inspectionReview").factory("inspectionReviewServices", ["$http", "config", inspectionReviewServices]);
function inspectionReviewServices($http, config) {
var serviceAddress = config.baseUrl + "api/InspectionReview/";
var service = {
getValues: getValues
};
return service;
function getValues(objectId, frequencyId) {
return $http.get(serviceAddress + "getValuesByObjectTypeId/" + objectId + "/" + frequencyId);
}
}
})();
And here I use it in controller to get data:
function checkInspection() {
var frequencyId = 5;
inspectionReviewServices.getValues($scope.object.Id, frequencyId).then(function (result) {
$scope.someData = result.data;
});
}
When I call function checkInspection
I need to wait until $scope.someData property is populated by data and only after it populated by data only then further rows can be executed.Currently I get promise and code executed further.
EDIT(according to the Darren's answer):
I changed my service and function that calls service:
function getValues2(objectId, frequencyId) {
return $http.get(serviceAddress + "getValuesByObjectTypeId/" + objectId + "/" + frequencyId).then(function (result) {
return result.data;
});
}
and here is function that calls for service in controller:
function checkInspectionReviewValidety() {
var frequencyId = 5;
return inspectionReviewServices.getValues2($scope.object.Id, frequencyId)
}
But still I dont get desired result.
How can I change checkInspection function to make it wait until $scope.someData property is populated by data?
Upvotes: 1
Views: 837