[英]How to search items from different views in Angular.js
In my home: 在我家:
.state('home',{
url: '',
views: {
'': {
templateUrl: 'views/main.html',
controller:'MainCtrl'
}
...
I loop through some books and also have a simple search field to filter the items: 我浏览了一些书,并有一个简单的搜索字段来过滤项目:
<input type="text" ng-model="search">
<article class="items" ng-repeat="book in allBooks | filter: search" >
This works, but I would like to add the input filed inside a sidebar, and have that sidebar in a seperate view - so that I would not have to duplicate it in every view. 这可行,但是我想将输入的文件添加到侧边栏中,并将该侧边放在单独的视图中-这样我就不必在每个视图中都重复它。 So in my index.html
I have the following code 所以在我的index.html
我有以下代码
<div ng-include ng-controller="MainCtrl" src="'views/sidebar.html'" class="sidebar"></div>
<div class="container" ui-view></div>
Assuming that this is a good practice, is there a way to add the search input field inside the sidebar, and still have it effect the loop in the home state? 假设这是一个好习惯,有没有办法在侧边栏内添加搜索输入字段,并且仍然在原始状态下影响循环?
Thanks 谢谢
You can make the home state a nested view of the sidebar. 您可以将主状态设为边栏的嵌套视图。 The ng-model that your filter is bound to in the sidebar view will then be available to the home state. 然后,在侧边栏视图中绑定到过滤器的ng-model将可用于原始状态。 The home state will delegate to the above sidebar scope when it doesn't find a search property on its own scope. 当主状态在自己的范围内找不到搜索属性时,其主状态将委派给上述侧边栏范围。
Here's my quick and dirty example: http://plnkr.co/gmUaDLSfJxOL42EPZ9ak 这是我快速又肮脏的示例: http : //plnkr.co/gmUaDLSfJxOL42EPZ9ak
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.