1
我在我的項目中使用了Siyfion's typeahead directive。Angular 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
};
我得到「對象」的數組作爲JSON從django
視圖。但問題是在我的HTML模板:
<input type="text" class='sfTypeahead' datasets='dataSet' ng-model='testname' />
由於dataSet
最初是空的,而異步調用正在取得我得到一個錯誤:
TypeError: Cannot read property 'name' of undefined
有沒有一種方法,如果我能請在dataSet
或datasets
中查找更改,以便在陣列allObjects
獲得填充後,DOM可能會刷新?
任何人都可以提出什麼可以在這裏完成
只需使用http://angular-ui.github.io/bootstrap/#/typeahead,而不是像這裏描述的那樣與promise一起工作nativelly:http://stackoverflow.com/a/15930592/1418796 –
它會支持bs3 ?我目前正在使用bs3。 –
是的,它應該與BS3沒有問題 –