所以这是我的工厂代码:运行代码后先
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)
获得其价值之前执行。
所以我的问题是我怎么能等到功能的getArray完成火我的代码:
$scope.arrayValue = simpleFactory.getArray($scope.searchWord);
谢谢,我读到的承诺,并设法解决这个问题:d – Erex