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?

1
  • did u check the console for any errors? Commented May 24, 2014 at 13:08

2 Answers 2

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 :)

Sign up to request clarification or add additional context in comments.

1 Comment

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.
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)" />

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.