1

My dropdown isn't being displayed even though I know it's getting the correct results. Code:

<input type="text" ng-model="newSelectedSemester" placeholder="Semester name" typeahead="semester.name for semester in getSemesters($viewValue)">

I can confirm that getSemesters is returning an array of Objects, each of which has the name property on them.

I have also already implemented this elsewhere on my site, so I know I'm pulling in the correct dependencies. What am I missing here?

girlcode
  • 3,155
  • 5
  • 27
  • 41

2 Answers2

2

Found out the problem.

I was using $http.get and I was returning from the "success" function, when I should have been returning from the "then" function. I don't know why this is but it worked :)

girlcode
  • 3,155
  • 5
  • 27
  • 41
  • The thing is that you have a `getSemesters($viewValue)` function that should return certain value. The success inside it doesn't acts a return for the function but for the get() action. You have to use a specific return or a then() than you did to get an actual value. – Puce Mar 30 '15 at 15:53
2

Here's another solution I came across that solved it for me:

$scope.solution = function(val){
    var data = {
        cards: val
    };
    var result = [];
    var deferred =  $q.defer();

    $http.post('/somepath', data)
        .success(function(response) {
            angular.forEach(response, function(card) {
                result.push(card);
            });
            return deferred.resolve(result);
        })
        .error(function(){
            /* error handling */
        });
    return deferred.promise;
};

And here's an example for the HTML part:

<input ... uib-typeahead="card as card.number + ' ' + card.suit for card in cardList($viewValue)" />
TrampGuy
  • 1,737
  • 1
  • 13
  • 9