Как использовать AngularJS typeahead с асинхронными и пользовательскими шаблонами для результатов

0

Я пытаюсь использовать Angular Typeahead для возврата объекта, а не поиска строки, но я не могу заставить его работать. Здесь мой код в контроллере:

$scope.getLocation = function(val) {
  return $http.get(API_PROVIDER.full_path + 'users.json', {
    params: {
      first_name: val,
      _role: 'voiceArtist'
    }
  }).then(function(resultonse){
    return resultonse.data.users.map(function(item){
      return item;
    });
  });
};

И, на мой взгляд,

<input type="text" ng-model="asyncSelected" placeholder="Search here" typeahead="name.first_name for name in getLocation($viewValue) | filter:{first_name:$viewValue}" typeahead-loading="loadingLocations" class="form-control">
<i ng-show="loadingLocations" class="fa fa-spin fa-refresh"></i>

Но все, что я верну, - это строка. Что мне не хватает?

Теги:
typeahead

1 ответ

0

Я решил в конце. Это был тот порядок, из-за которого я ошибался. Вместо

<input type="text" ng-model="asyncSelected" placeholder="Search here" typeahead="name.first_name for name in getLocation($viewValue) | filter:{first_name:$viewValue}" typeahead-loading="loadingLocations" class="form-control">

Должно быть:

<input type="text" ng-model="voice.voiceArtist" placeholder="Search voice artist" typeahead="state as state.first_name for state in getLocation($viewValue) | filter:{name:$viewValue}" class="form-control">

Ещё вопросы

Сообщество Overcoder
Наверх
Меню