Just starting here with Firebase. I'm trying out a simple blog using the new SDK and angular. So far I can add an array of articles that contains the title, author, text, etc. But I'd Like to add an Array of Comments to each article. Not sure about the best way to accomplish this. My instinct wants to make the Comments nest under the unique ids of the articles. But the Docs are against all things unflat.
var postref = firebase.database().ref('articles');
var commentsref = firebase.database().ref('articles').child('comments')
$scope.articles = $firebaseArray(articlesref);
$scope.comments = $firebaseArray(commentsref);
$scope.addarticles = function() {
$scope.articles.$add({
title: $scope.newTitle,
author: $scope.newAuthor,
text: $scope.newPost,
date: firebase.database.ServerValue.TIMESTAMP,
});
$scope.newTitle = null;
$scope.newAuthor = null;
$scope.newPost = null;
$scope.newDate = null;
};
$scope.addComment = function() {
text: $scope.newText,
});
$scope.newText = null;
};
So now I'm trying to have the Comments bind to the appropriate article. Here's the markup
<form ng-submit="addArticle()">
<p class="entry">
<input ng-model="newTitle" placeholder="Title" class="form-control">
</p>
<p class="entry">
<input ng-model="newAuthor" placeholder="Author" class="form-control">
</p>
<p class="entry">
<textarea ng-model="newText" cols="30" rows="6" placeholder="Text"></textarea>
</p>
<div>
<button type="submit" class="button" ng-click="post=!post">Add post</button>
<button ng-click="post=!post" class="button">Cancel</button>
</div>
</form>
<h2>{{post.title}}</h2>
<h4>{{post.author}}></h4>
<h4>{{post.text}}</h4>
<h6>{{post.date | date:'medium' | date:'HH:mm:ss'}</h6>
<div>
<form ng-submit="addComment()">
<h6>{{post.Comments}}</h6>
I'm sure the answer(s) is really obvious and I'll feel like a doofus. Thanks in advance.