【发布时间】:2015-02-26 21:21:20
【问题描述】:
我有以下使用 AngularJS 和 Angular Bootstrap Typeahead 小部件的代码。问题是它只返回一个错误属性长度“未定义”。任何帮助将不胜感激。
HTML
<h4>Asynchronous results</h4>
<pre>Model: {{asyncSelected | json}}</pre>
<input type="text" ng-model="asyncSelected" placeholder="Patients loaded via $http" typeahead="result.patient.drug.drugindication for result in getPatient($viewValue)" typeahead-loading="loadingPatients" class="form-control">
<i ng-show="loadingPatients" class="glyphicon glyphicon-refresh"></i>
Javascript
$scope.getPatient = function(val) {
return $http.get('https://api.fda.gov/drug/event.json', {
params: {
search: 'patient.drug.drugindication:' + val
}
}).then(function(response){
//the following console log returns the data just fine
console.log(response.data.results)
return
{
result: response.data.result
}
});
};
错误:
TypeError: 无法读取未定义的属性“长度”
【问题讨论】:
标签: angularjs angularjs-scope angular-ui-bootstrap bootstrap-typeahead angular-ui-typeahead