だから、これは私の工場コードです:
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)
前に実行されることです。
したがって、私の質問は、getArray 関数が終了してコードを起動するまで待つ方法です。$scope.arrayValue
$simpleFactory.getArray($scope.searchWord)
$scope.arrayValue = simpleFactory.getArray($scope.searchWord);