javascript - How to add items to a specific dictionary within an item in a list with AngularFire? -
The code below shows a list from the firebase and shows the related comment field for each item in the list. The user can comment on that item and it will update the comment field for that item in the list. Currently, every time a comment is made, it overwrites the previous one, but I would like to save all the comments.
How do I make it, so that every comment should be added every time, the last ones are also saved?
indx.html app.js The following is the data structure that is generated within the firebase {helloworldtest: {-JSQhsAnY5zhf0oVKfbb: {title: "nameA", comment: "second comment"}, -JSQhsAnY5zhf0oVKfbb: {title: "Name B", Comment: "Second Comment"}}} However, I want to create the following where there is a 'comment' branch with all the comments. {Comment: "Comment": {Comment: "Second Comment"}, - JSQhsAnY5zhf0oVKfbb: {Comment: "First Comment", {comment: {comment: {- JSQhsAnY5zhf0oVKfbb: }}}, {-JSQhsAnYdfdfdffbb: {title: "nameA", comments: {- JSQhsAnY5zhf0oVKfAb: {note: "another commented"}, - JSQhsAnY5zhf0oVKfbb: {note: "first comment"}}}} I have tried to change it I have also tried to use: In a comment field Instead of saving comments, use a list as a comment and use In addition to this. Instead, consider keeping the comments in their own way in their own way.
& lt; Div ng-app = "MyApp" ng controller = "MyCtrl" & gt; & Lt; Div ng-repeat = "data (id, item)" & gt; & Lt; H2 & gt; {{Item.title}} & lt; / H2 & gt; & Lt; Input ng-model = "item.comment" & gt; & Lt; / Input & gt; & Lt; Button type = "submit" ng-click = "add comment (id)" & gt; Comment & lt; / Button & gt; & Lt; / Div & gt; & Lt; / Div & gt;
angular.module ('MyApp', ['firebase']) .controller ('MyCtrl 'function MyCtrl ($ scope, $ firebase) {var deflect = "https://helloworldtest.firebaseio.com"; var ref = new Firebase (inflection); $ scope.data = $ firebase (ref); $ scope. CommentAdd = function (id) {$ scope.data. $ Save (id);};});
$ scope.data $ Save (id); With
$ scope.data. $ Add (id);
$ scope.data [id]. $ Add ({foo: "bar"})
push or
$ add .
Comments
Post a Comment