I am creating a function in angular that I want to grab all the blog posts with a category matching the button clicked, there are 3 different fields in my firebase titled category1, category2, and category3. Wehn a user clicks newsletter for example I want to see all posts that have the category newsletter whether it is stored in category1, category2, or category3. I thought I could concat()them. But it is not working. here is my function where I am trying this.
$scope.sortByNewsletter = function() {
var postsNumNews1 = $firebaseArray(ref.child('pPosts').orderByChild("category1").equalTo("Newsletters"));
var postsNumNews2 = $firebaseArray(ref.child('pPosts').orderByChild("category2").equalTo("Newsletters"));
var postsNumNews3 = $firebaseArray(ref.child('pPosts').orderByChild("category3").equalTo("Newsletters"));
console.log(postsNumNews1);
console.log(postsNumNews2);
console.log(postsNumNews3);
var $scope.postsNum = postsNumNews1.concat(postsNumNews2,postsNumNews3);
console.log($scope.postsNum);
}
I am then ng-repeating on postsNum to display them to the page like this.
<div class="blog-item" dir-paginate="post in postsNum | orderBy: 'postedDate': true | filter:searchPosts | itemsPerPage: 1">
<img class="img-responsive img-rounded" src="{{ post.imageOne }}" width="100%" alt="" />
<div class="blog-content">
<h3><strong>{{ post.title }}</strong></h3>
<h4><strong>{{ post.subTitle }}</strong></h4>
<div class="entry-meta">
<span><i class="fa fa-user"></i> {{ post.postedBy }}</span>
<span><i class="fa fa-folder"></i> {{ post.category1 }} {{ post.category2 }} {{ post.category3 }}</span>
<span><i class="fa fa-calendar"></i> {{ post.datePosted }}</span>
</div>
<br>
<p>{{ post.paragraph1 }}</p>
<p>{{ post.paragraph2 }}</p>
<p>{{ post.paragraph3 }}</p>
</div>
</div>
I also thought I could maybe pass in multiple "categories" into my orderByChild() but that isn't working either.