【发布时间】:2017-10-13 17:05:20
【问题描述】:
我试图在 3 个字符后发起请求,但是一旦键入 3 个字符,我就会收到 No records found 错误,之后我可以找到服务调用已完成,但自动完成中没有显示任何内容(只有错误消息在自动完成下拉菜单下)。我在这里缺少什么?
HTML 代码:
<angucomplete-alt id="angu_{{$index}}"
placeholder="Search people"
remote-api-handler="search"
remote-url-data-field="results"
title-field="fullName"
minlength="3"
input-class="form-control form-control-small"
selected-object="selected"
selected-object-data="$index"
clear-selected="true"/>
API 远程处理程序
$scope.search = function(str, timeoutPromise) {
return $timeout(function () {
$scope.input = {};
$scope.input.userId = "";
$scope.input.name = str;
$scope.input.system = "";
$scope.input.officeNumber = "";
$scope.input.department= "";
// server call and get the response to $scope.organisationNames
var promise = genericAPIService.doApiCall(url, appConstant.POST,
JSON.stringify($scope.input));
promise.then(
function(payload) {
console.log(payload);
$scope.organisationNames = payload.data.result.data.List;
$scope.results = [];
$scope.organisationNames.forEach(function(organisation) {
if ((organisation.fullName.toLowerCase().indexOf(str.toString().toLowerCase()) >= 0)) {
$scope.results.push(organisation);
}
});
return scope.results;
},
function(errorPayload) {
$log.error('failure loading role json', errorPayload);
}).finally(function(){
$scope.loading = false;
});
}
},5000);
};
尝试了另一个版本:
<angucomplete-alt id="angu_{{$index}}"
placeholder="Search people"
selected-object="selectedBusiness"
selected-object-data="$index"
clear-selected="true"
input-class="form-control
form-control-small"
remote-api-handler="searchAPI"
remote-url-data-field="responseData.data"
title-field="fullName" minlength="3" />
$scope.searchAPI = function (userInputString, timeoutPromise) {
$scope.approversAndEndorsersInput = {};
return $timeout(function () {
$scope.approversAndEndorsersInput.userId = "";
$scope.approversAndEndorsersInput.name = userInputString;
$scope.approversAndEndorsersInput.system = "";
$scope.approversAndEndorsersInput.officeNumber = "";
$scope.approversAndEndorsersInput.department= "";
return $http.post(appConstant.selfDomainName+appConstant.getApproversAndEndorsersList, JSON.stringify($scope.approversAndEndorsersInput), {timeout: timeoutPromise});
}, 1000);
}
【问题讨论】:
-
你用
genericAPIService打了什么REST端点 -
当
errorPayload处理程序未能重新抛出错误时,链中的下一个.then块将执行。为了跳过后续的.then块,重新抛出错误很重要。 -
@georgeawg:它根本没有进入错误处理程序。在服务调用结束之前执行 Angu 完整指令......因为没有找到记录......我猜是这样......
-
@bowofola: 端点正在提供数据.. 在点击 url 之后.. 或者应该以其他方式提供?
-
很难重现您所看到的问题。什么是
angucomplete-alt?第三方库或您创建的指令?