AngularJS中的搜索篩選功能對我來說不起作用。在AngularJS中使用搜索字段進行篩選
我navbar.html:
<input type="text" placeholder="Search" data-ng-model="searchQuery">
在視圖模板:
<ul class="userlist">
<li class="list" data-ng-repeat="user in users | filter: searchQuery">
<!--users show here-->
</li>
</ul>
在index.html的:
<div data-ng-include data-src="'./templates/navbar.html'"></div>
<div data-ng-view></div>
我沒有收到任何錯誤消息,它只是不起作用。 這是因爲模型在單獨的模板中?
2小時後,我仍然沒有線索如何實現這一點。 但我想我越來越近了。當我更改searchQuery字符串時,它會過濾結果。 所以我需要了解的是我如何從導航欄模板(包含在ng-include中)控制此字符串。
兩個控制器:
//NAVBAR template controller
app.controller('NavbarController', ['$scope', '$location',
function ($scope, $location) {
}]);
//LIST page controller
app.controller('ListCtrl', ['$scope', '$http',
function ($scope, $http) {
$scope.listpage = {'searchQuery' : ''};
//...
}]);
view.html:
<li data-ng-repeat="user in users | filter: listpage.searchQuery">
navbar.html
<input type="text" data-ng-model="listpage.searchQuery">
如何改變末頁對象在導航欄模板(這是包含在ng-include中),以便將其應用於過濾器中?
你能做小提琴嗎 – 2014-11-21 12:47:41