So this is my factory code:
app.factory('simpleFactory', function ($http) {
var factory = {};
factory.getArray = function (srchWord) {
**Here i have a code that uses $http to fill a array called result with values.
return result;
};
return factory;
});
And this is the code inside my scope:
$scope.search = function() {
$scope.arrayValue = simpleFactory.getArray($scope.searchWord);
$scope.booleanValue = ($scope.arrayValue.length <= 0); // <-- PROBLEM! This gets executed before getArray() is finished.
};
My problem is that $scope.booleanValue = ($scope.arrayValue.length <= 0) is executed before $scope.arrayValue has gotten its value form $simpleFactory.getArray($scope.searchWord).
So my question is how I can wait until the getArray function is finished to fire my code:
$scope.arrayValue = simpleFactory.getArray($scope.searchWord);