md-autocomplete无法正常工作

时间:2016-03-27 06:08:31

标签: angularjs autocomplete angular-material md-autocomplete

我正在使用此代码搜索电影,因为用户在自动填充框中键入电影名称。我在控制台上获得结果但是没有显示项目文本 HTML

<md-autocomplete md-selected-item="selectedMovie"
    md-search-text-change="searchMovie(searchText)"
    md-search-text="searchText"
    md-selected-item-change="selectedItemChange(movie)"
    md-items="movie in movies"
    md-item-text="movie.title"
    md-min-length="1" 
    placeholder="Search Movies">
  <md-item-template>
        <span md-highlight-text="searchText" md-highlight-flags="^i"> 
          {{movie.title}}
        </span>
    </md-item-template>
    <md-not-found>
        No Movies matching were found.

    </md-not-found>
</md-autocomplete>

的js

 $scope.searchMovie = function (text) {
            $http.get('api/movie', {
                params: {
                    searchMovieName: text
                }
            }).success(function (data, status) {
                console.log(data.results);
                console.log(status);
                $scope.movies = data.results;
            }).error(function (err) {
                console.log(err);
            });
        };

1 个答案:

答案 0 :(得分:2)

JS

IndexError

在你的HTML中

$scope.searchMovie = function(text) {
  return $http.get('api/movie', {
    params: {
      searchMovieName: text
    }
  });
}

$ http.get返回可以在md-items中使用的promise对象。像md-items =“searchMovie(searchText)中的电影”