gpt4 book ai didi

javascript - Angularjs $http 不按 promise 返回对象

转载 作者:行者123 更新时间:2023-11-28 17:28:44 26 4
gpt4 key购买 nike

我正在使用带有 Angular Material 的 angularjs 但它没有从 $http 返回对象我的完整代码笔在 http://codepen.io/milindsaraswala/pen/rLjLMX

<md-autocomplete md-input-name="autocompleteField" md-no-cache="ctrl.noCache" md-selected-item="ctrl.selectedItem" md-search-text="ctrl.searchText"
md-items="item in ctrl.querySearch(ctrl.searchText)" md-item-text="item.display" md-min-length="0"
md-floating-label="Station" flex required>
<md-item-template>
<span md-highlight-text="ctrl.searchText" md-highlight-flags="^i">{{item.display}}</span>
</md-item-template>
<div ng-messages="searchForm.autocompleteField.$error" ng-if="searchForm.autocompleteField.$touched">
<div ng-message="required">You <b>must</b> have a favorite state.</div>
<div ng-message="minlength">Your entry is not long enough.</div>
<div ng-message="maxlength">Your entry is too long.</div>
</div>
</md-autocomplete>

我做错了什么!!

最佳答案

loadAll() 函数需要返回一个 promise。

    function loadAll() {
var deferred = $q.defer();
var url = "http://webdev.kuwaitairways.com/_api/lists/getbytitle('KAC_Stations')/items?$select=Id,City_Code,City_Name_EN&$filter=Active eq 1&$orderby=City_Name_EN asc";
$timeout(function() {
httpGetService.getDataItem(url).then(function(result) {
var allStations = [];
angular.forEach(result, function(b) {
var station = {
value: b.City_Code.toLowerCase(),
display: b.City_Name_EN + '(' + b.City_Code + ')'
}
allStations.push(station);
});
deferred.resolve(allStations);
}, function(err) {
deferred.reject(err);
})
}, 1000);
return deferred.promise;
}

这是工作示例。 http://codepen.io/mkl/pen/XKpRaP

关于javascript - Angularjs $http 不按 promise 返回对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38019856/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com