您好我正在尝试创建一个基本的全局搜索,它将根据存在的视图(控制器)过滤页面上的结果。
搜索控制器:
<form ng-controller="searchCtrl">
<div class="container col-md-12">
<div class="row margin col-md-2">
<label>Search</label>
<input ng-model="searchSite" type="text" class="form-control" />
</div>
</div>
</form>
查看控制器示例:
.state('Blog', {
url: '/blog',
controller: 'BlogCtrl as blg',
templateUrl: 'blog.html',
title: 'Blog'
})
博客控制器:
controllersModule.controller('BlogCtrl', ["$scope", "postsDB", function($scope, postsDB) {
//postsDB is the factory pulling the API
postsDB.query(function(posts){
$scope.myPosts = posts;
})
}]);
HTML输出
<div class="card-image waves-effect waves-block waves-light">
<img class="activator" src="images/sample-1.jpg">
</div>
<div class="card-content">
<span class="card-title activator grey-text text-darken-4">{{post.Title}}<i class="material-icons right">more_vert</i></span>
<p><a href="#">Read More</a></p>
<p>By: {{post.Author}} Published on: {{post.Published | date:'mediumDate'}}</p>
</div>
<div class="card-reveal">
<span class="card-title grey-text text-darken-4">{{post.Title}}<i class="material-icons right">close</i></span>
<div>{{post.Intro}}</div>
<p ng-bind-html="post.Body">{{post.Body}}</p>
</div>
</div>
</div>
我使用此post作为参考并设置&#34; searchSite&#34;使用$rootScope
查询全局对象:
controllersModule.controller( 'searchCtrl','$scope', '$rootScope','$firebaseArray',function($scope, $rootScope, $firebaseArray) {
$rootScope.searchSite = $firebaseArray('');
});
将此转换为数组的原因是因为我收到了错误Error: [filter:notarray] Expected array
,但即使在更改错误之后,我仍然会遇到相同的错误。