我正在尝试实现一个简单的bootstrap typeahead,其中响应通过http调用获取。我正在完美地接收响应但似乎服务调用的最新值未绑定到范围变量,其中typeahead是读数。
$ scope.onChangeCallBack = function(viewValue){
var program = $scope.program.name;
var occupancyType = $scope.occupancyType.name;
var isStorage = $scope.isBuildingStorage;
var isFranchise = $scope.isFranchise;
var isLeased = $scope.isLeased;
var isBarBuilding=$scope.isBarBuilding;
console.log("program:"+program+"//occupancyType:"+occupancyType+"//isStorage:"+isStorage+"//isFranchise:"+isFranchise+"//+isBarBuilding"+isBarBuilding+"//viewValue"+viewValue);
var param =
{
searchString: viewValue,
filterCriteria: {
isBar: true/*isBarBuilding*/,
isFranchise: false/*isFranchise*/,
isMercantile: true/*isLeased*/,
program: program,
occupancyType:"tennat"
}
}
var promise = AEBusinessOwnerService.getBuildingClassification(param);
promise.then(function(data) {
console.log(JSON.stringify(data.results));
$sccope.classificationTypeAhead = data.results;
});
};
键入4个单词后显示的搜索结果仅在输入第5个字符后才可见。我不知道丢失了什么。
答案 0 :(得分:0)
如果我不得不猜测,我猜错AEBusinessOwnerService.getBuildingClassification
并未返回与Angular的摘要周期集成的承诺(即基于$的内容) q)。试着这样做:
promise.then(function(data) {
$scope.$apply(function() {
console.log(JSON.stringify(data.results));
$scope.classificationTypeAhead = data.results;
});
});
答案 1 :(得分:0)
这是Jonathan的支持答案,但我还不能发表评论:
promise.then(function(data) {
$scope.$apply(function() {
console.log(JSON.stringify(data.results));
$scope.classificationTypeAhead = data.results;
});
});
如果我这样做,我得到错误错误:[$ rootScope:inprog] $ digest 已在进行中
正如错误所述,$ digest正在进行中,您可以通过执行此操作来解决它
if(!$scope.$$phase) {
$scope.$apply(function() {
console.log(JSON.stringify(data.results));
$scope.classificationTypeAhead = data.results;
});
}