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

  & 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;   

app.js

  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);};});   

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

  $ scope.data $ Save (id); With   

  $ scope.data. $ Add (id);   

I have also tried to use:

  $ scope.data [id]. $ Add ({foo: "bar"})    

In a comment field Instead of saving comments, use a list as a comment and use push or $ add .

Controller = "MyCtrl" & gt; & Lt; Div ng-repeat = "data (id, item)" & gt; & Lt; H2 & gt; {{Item.title}} & lt; / H2 & gt; & Lt; Input ng-model = "new comment" & gt; & Lt; / Input & gt; & Lt; Button type = "submit" ng-click = "add comment (id, new comment)" & gt; Comment & lt; / Button & gt; & Lt; / Div & gt; & Lt; / Div & gt; MyCtrl ($ scope, $ firebase) {var furl = "https://helloworldtest.firebaseio.com"; Var ref = new firebase (Fell + '/ item'); $ Scope.data = $ firebase (referee); Var $ comments = $ firebase (commentsRef); $ Scope.addComment = function (id, new comment) {ref.child (id) .child ( 'comments'). Push (newcomment); }; });

In addition to this. Instead, consider keeping the comments in their own way in their own way.

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -