I've just started out with Angular, and I did the codeschool tutorial. I took it a step further and wanted to push form data to a json file.
I'm getting the correct response where the information is posted, but the file is not being updated. I've tried this locally and on a development server.
This is my directive code:
//---------------------------------------//
// Lets user add a review to site
app.directive("productAddReview", function($http) {
return {
restrict: 'E',
templateUrl: 'directives/product-add-review.html',
controller: function($http) {
// gets a blank review
this.review = {};
// sets today's date as a variable
this.review.date = Date.now();
// adds a review
this.addReview = function(product) {
product.reviews.push(this.review); // adds review to dom
$http.post('../data/products.json', this.review) //updates json file
this.review = {}; // resets review upon completion
};
},
controllerAs: 'reviewCtrl',
};
});
Example json response upon review submit:
author: "[email protected]"
body: "this is a test"
date: 1443540061192
stars: 5
Source: {"date":1443540061192,"stars":5,"body":"this is a test","author":"[email protected]"}