所以这是我的工厂代码:
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);