Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Hi I've started to make a comments module for my website with Angular, and I am stucking now at one point: updating my JSON file which contains the comments.

Here is the JSON:

[
{
"page": "dashboard",
 "text":"first comment",
 "author":"vince"
  },
  {
      "page": "dashboard",
      "text":"second comment",
      "author":"vince"
},
{
    "page": "angular_crawling",
    "text":"second comment",
    "author":"vince"
}

]

And the function which add comments to the $scope data, but it's not changing the JSON file

$scope.addcommentaire = function() { console.log(this.textMessage); console.log(this.auteur); console.log(document.getElementById('hiddenpage').value); var onecomment= {page:document.getElementById('hiddenpage').value, text:this.textMessage,author:this.auteur }; $scope.commentaires.unshift(onecomment); };

how to add data in a JSON file with angular or javascript ? Is it possible?

share|improve this question
    
How do you expect to update a file on the server from code that runs only on the client? You need something that runs on the server too. –  Dark Falcon 2 days ago
    
node.js is the only solution? –  vincent T 2 days ago
    
Of course not. You could do it in PHP, ASP, ASP.NET, Node.js, or any other server-side language, but you need something on the server. You could even host your site out of S3 and update it with S3 calls, but it still has to have something on the server (in that case, S3's API) –  Dark Falcon 2 days ago
    
You could use MongoDB's REST API if you want to skip the server part. –  Goodzilla 2 days ago
    
@Goodzilla: Which is still running MongoDB on the server (But doesn't require him to write any server-side code.) –  Dark Falcon 2 days ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.