1
我想使用angularjs過濾器方法進行搜索,但它不工作。我在控制檯中沒有收到任何錯誤,但仍然沒有顯示搜索結果。有人可以幫助我做到這一點。AngularJS使用過濾器不工作的搜索
這是我的controller.js代碼:
.controller('SearchController',
[
'$scope',
'dataService',
'$location',
'$routeParams',
function ($scope, dataService, $location, $routeParams){
$scope.searchMovies = [ ];
$scope.searchCount = 0;
var getSearchResult = function (terms) {
dataService.getSearchResult(terms).then(
function (response) {
$scope.searchCount = response.rowCount + ' movies';
$scope.searchMovies = response.data;
$scope.showSuccessMessage = true;
$scope.successMessage = "All movie Success";
},
function (err){
$scope.status = 'Unable to load data ' + err;
}
); // end of getStudents().then
};
if ($routeParams && $routeParams.term) {
console.log($routeParams.term);
getSearchResult($routeParams.term);
}
}
]
);
這是services.js代碼:
this.getSearchResult = function (terms) {
var defer = $q.defer(),
data = {
action: 'search',
term: terms
}
$http.get(urlBase, {params: data, cache: true}).
success(function(response){
defer.resolve({
data: response.ResultSet.Result,
rowCount: response.RowCount
});
}).
error(function(err){
defer.reject(err);
});
return defer.promise;
};
這是我的app.js代碼:
. when('/search', {
templateUrl : 'js/partials/search.html',
controller : 'SearchController'
}).
這是search.html代碼:
<div>
<label>Search: <input ng-model="searchMovie"></label><br><br><br><br>
</div>
<table class="table table-hover table-bordered">
<thead>
<tr>
<th>Title</th>
<th>Description</th>
<th>Category</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="search in searchMovies | filter:searchMovie">
<td>
{{search.title}}
</td>
<td>
{{search.description}}
</td>
<td>
{{search.name}}
</td>
</tr>
</tbody>
</table>
搜索數據正在從數據庫中檢索。我測試了SQL,它工作正常。只是你的問題是在angularjs服務器端。謝謝。
發表您的html頁面 – StarsSky
@StarsSky我已經在問題 – anonymous5671
中加入了html代碼hello,你如何設置url params?如果它們未設置,則searchMovies數組將保持爲空。 – Nora