【发布时间】:2017-04-15 23:45:21
【问题描述】:
我有一个使用 angular uib-typeahead 的应用程序。
通过ajax调用远程加载数据。
我需要过滤结果以仅显示包含 $viewValue 字符串的“名称”的结果。
这是我的代码。我的问题是数据永远不会被过滤。
我做错了什么?
//标记
<input type="text" ng-model="modelo.tuss" placeholder="Select TUSS"
uib-typeahead="item as item.name for item
in getTabelaTUSS($viewValue) | filter:{name:$viewValue}"
class="form-control">
//控制器
angular.module("clinang").controller('exameCtrl',['$scope', function($scope) {
var prof=[{"id":1,"name":"John Prof"},
{"id":2,"name":"Mary Prof"}];
$scope.getTabelaTUSS = function(val) {
return dataService.getTabelaTUSS().then(function(response){
return prof; //only to simulate results to test
});
};
}]);
更新的控制器:
//first option - geting rid off view filter and making local filter in controller
angular.module("clinang").controller('configAgendaAddProcedimentosCtrl',['$scope','dataService','$state','$filter',function($scope,dataService,$state,filter){
$scope.getTabelaTUSS = function(val) {
return dataService.getTabelaTUSS().then(function(response){
return filterFilter(response.data, val);
});
};
}]);
//second option - using view filter and no local filter in controller
//I also tried without success
angular.module("clinang").controller('configAgendaAddProcedimentosCtrl',['$scope','dataService','$state','$filter',function($scope,dataService,$state,filter){
$scope.getTabelaTUSS = function(val) {
return dataService.getTabelaTUSS().then(function(response){
return response.data;
});
};
}]);
【问题讨论】:
标签: angularjs filter angular-ui-bootstrap