2016-06-09 74 views
0

我想實現一個簡單的引導程序typeahead響應獲取通過http調用。我收到了完美的響應,但它似乎從服務調用的最新值是沒有被綁定到從哪個typeahead正在讀取的範圍變量。無法綁定來自http調用的最新數據提前

$ scope.onChangeCallBack =功能(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個字符後是可見的。我不知道有什麼缺失。

+1

你還沒有修復你的代碼中的錯字嗎?在承諾中您有$ sccope.classificationTypeAhead。 $範圍拼寫錯誤。 – DanielC

+0

是的我修正了它。Ranjan –

回答

0

如果我不得不猜測,我猜想AEBusinessOwnerService.getBuildingClassification沒有返回一個與Angular的摘要循環(即基於$ q的東西)集成的承諾。試着這樣做:

promise.then(function(data) { 
    $scope.$apply(function() { 
     console.log(JSON.stringify(data.results)); 
     $scope.classificationTypeAhead = data.results; 
    }); 
}); 
+0

如果我這樣做,我得到錯誤:[$ rootScope:inprog] $ digest已在進行中 - Ranjan –

+0

然後'AEBusinessOwnerService.getBuildingClassification'正在爲你做這件事,而這是解決您的問題。 –

0

這是一個支持的答案喬納森的,但我不能評論卻又如此:

promise.then(function(data) { 
    $scope.$apply(function() { 
     console.log(JSON.stringify(data.results)); 
     $scope.classificationTypeAhead = data.results; 
    }); 
}); 

If I do as above i get the error as Error: [$rootScope:inprog] $digest already in progress

由於錯誤陳述,一個$消化過程中,你可以通過這樣做來解決它

if(!$scope.$$phase) { 
    $scope.$apply(function() { 
     console.log(JSON.stringify(data.results)); 
     $scope.classificationTypeAhead = data.results; 
    }); 
} 
相關問題