[英]Angular typeahead : watch for dataset change
我在我的項目中使用Siyfion的typeahead指令 。
我在控制器中所做的是這樣的:
$http({method: 'GET', 'url': CONFIG.SOMEURL})
.success(function(data, status, headers , config){
if(status==200)
{
$scope.objects = data;
for(i=0; i < $scope.objects.length; i++){
$scope.allObjects.push($scope.objects[i].name);
}
console.log($scope.allObjects);
$scope.dataSet = {
name : 'objs',
local : $scope.allObjects
};
我從django
視圖中獲得了一個'對象'數組作為json。 但是問題出在我的HTML模板中:
<input type="text" class='sfTypeahead' datasets='dataSet' ng-model='testname' />
由於在進行異步調用時dataSet
最初為空,所以出現錯誤:
TypeError: Cannot read property 'name' of undefined
有沒有一種方法可以查找dataSet
或datasets
變化,以便一旦數組allObjects
被填充,DOM可能就可以刷新?
任何人都可以建議可以在這里做什么
全面披露:我是上述指令的作者。
本質上,當Typeahead.js和Bloodhound專為您設計時,您正在嘗試在Angular中進行所有預取。 仔細看看https://twitter.github.io/typeahead.js/examples/,並特別注意Bloodhound建議引擎。
也許有些用處:
注意:您正在使用的指令版本(9個月前)不支持更新數據集局部變量,但現在支持更新,因此您可以按照需要這樣做。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.