그래서이 내 공장 코드 :실행 코드를 먼저 한 후
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;
});
그리고 이것은 내 범위 내 코드입니다 :
$scope.search = function() {
$scope.arrayValue = simpleFactory.getArray($scope.searchWord);
$scope.booleanValue = ($scope.arrayValue.length <= 0); // <-- PROBLEM! This gets executed before getArray() is finished.
};
내 문제가 $scope.booleanValue = ($scope.arrayValue.length <= 0)
을 것입니다 $scope.arrayValue
이 값 형식 $simpleFactory.getArray($scope.searchWord)
을 얻기 전에 실행됩니다.
$scope.arrayValue = simpleFactory.getArray($scope.searchWord);
덕분에, 내가 약속에 대해 읽고, 문제를 해결하기 위해 관리 : D – Erex