使用此代码,我总是得到TypeError: Cannot read property 'success' of undefined。我也尝试过使用 .then 而不是 .success 但我得到了同样的错误。经过十多个小时的谷歌搜索后,我有点绝望......
html:
<div ng-controller="search_interest" layout="column">
<md-chips ng-model="ctrl.selectedVegetables" md-autocomplete-snap md-require-match>
<md-autocomplete
md-selected-item="selectedItem"
md-search-text="searchText"
md-items="item in getInterest(searchText)"
md-item-text="item.name"
placeholder="Search for a vegetable">
<span md-highlight-text="searchText">{{item.name}} :: {{item.type}}</span>
</md-autocomplete>
<md-chip-template>
<span>
<strong>{{$chip.name}}</strong>
<em>({{$chip.type}})</em>
</span>
</md-chip-template>
</md-chips>
</div>
和js:
var app = angular.module('autocomplete_app', ['ngMaterial']);
app.controller('search_interest',
function($scope, $http){
$scope.searchText = '';
$scope.selectedItem = undefined;
function getInterest($scope){
$http.get("someurl.php?query=" + $scope.searchText)
.success(function(data){
$scope.interest = data;
console.log('data', JSON.stringify(data));
});
};
});