나는 각도 uib-aheadahead를 사용하는 앱을 가지고 있습니다.uib-typahead를 사용한 AngularJs 필터링이 작동하지 않습니다.
데이터는 ajax 호출로 원격으로로드됩니다.
"name"이 $ 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
});
};
}]);
이 업데이트 컨트롤러 // : 당신이 return prof;
과 다음 블록을 교체하는 경우
//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;
});
};
}]);
감사합니다. 나는 더 잘 설명 할 것이다. 내가 코멘트 코드에서 말했듯이 나는 단지 prof를 사용하여 테스트에서 "response.data"가 실제로 필요하고 뷰 또는 컨트롤러에 "$ viewValue"를 사용하여 필터 "응답"이 필요합니다. –
@LuizAlves 나는 이해하고 나의 제안을 적용 할 수도있다. scope variable에'response.data'를 할당하고 뷰에서 사용하십시오. – Hoa
안녕하세요. 작동하지 않습니다. 나는 다음과 같이 컨트롤러에 필터를 시도했다. $ scope.getTabelaTUSS = function (val) { return dataService.getTabelaTUSS(). (function (response) { return filterFilter (response.data, val); }); }; 또는 "return response.data;"를 사용하여보기 그러나 아무것도 작동하지 않습니다. –