0
votes

I have this small problem with Typeahead directive here is my code so far:

$scope.getUserNames = function (input) {
            return $http.get(ApplicationConstants.apiUrl + 'api/Users/UserNames', {
                headers: { 'ContentType': 'application/json' },
                params: {
                    input: input
                }
            }).then(function (response) {
                $log.debug('GetUserNames:', response.data);
                return response.data;
            }, function (error) {
                $log.debug(error);
            });
        };

This is as required by the documentation - the promise is being returned and the contents of the response data are as follow : ['username1','username2',...]

Then in markup I have following code:

{{userNameSelected}}
                    <input type="text" ng-model="userNameSelected" placeholder="Type the username" typeahead="val as val for val in getUserNames($viewValue)" class="form-control">

I've tried using "val for val in getUserNames($viewValue)" but it also doesn't help. The problem is that the model gets updated correctly but no dropdown under the typeahead input is being shown - no results. Am I doing something wrong ? Just to mention I have latest angular and angular-ui-bootstrap

1

1 Answers

0
votes

When you click the input or type something in, does your input have an empty dropdown or not even that? Did you check if you request response is coming through? Since you've tried using val for val in getUserNames I would guess your problem is you response.

Also, try removing your headers: { 'ContentType': 'application/json' },, sometimes you may forget to configure your service's allowed requests and so. You should be gettin something like

Request header field ContentType is not allowed by Access-Control-Allow-Headers.

in your console

Hope it helps!