您好我正在尝试创建一个基本的全局搜索,它将根据存在的视图(控制器)过滤页面上的结果。
搜索控制器:
<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>
我使用这篇文章作为参考,并将“searchSite”查询设置为全局对象$rootScope
:
controllersModule.controller( 'searchCtrl','$scope', '$rootScope','$firebaseArray',function($scope, $rootScope, $firebaseArray) {
$rootScope.searchSite = $firebaseArray('');
});
将其转换为数组的原因是因为我收到了错误Error: [filter:notarray] Expected array
,但即使更改了它,我仍然收到同样的错误。