I am using Siyfion's typeahead directive in my project.
What I do in my controller is something like this :
$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
};
I get an array of 'objects' as json from django
view. But the problem is in my HTML template:
<input type="text" class='sfTypeahead' datasets='dataSet' ng-model='testname' />
Since the dataSet
initially is empty while the async call is being made I get an error :
TypeError: Cannot read property 'name' of undefined
Is there a way if I can look for changes in dataSet
or datasets
so that as soon as the array allObjects
gets populated,The DOM gets refreshed maybe ?
Can anyone suggest what could be done here