Folks I have a form on my website who's data I want to store in a json file.
Here is the code for the form:
<form>
<input ng-model="obj.firstname">
<input ng-model="obj.lastname">
<button ng-click="storedata()">Click here to store data</button>
</form>
My Angular code is as below:
var myApp = angular.module('app', ['ui.bootstrap.dialog','ngResource']);
myApp.controller('TestCtrl', function($scope,$dialog,TestResource) {
$scope.obj = {};
$scope.obj.firstname = "Mahatma";
$scope.obj.lastname = "Gandhi";
$scope.storedata = function() {
console.log("Storing Data now");
TestResource.save($scope.obj);
console.log("Data should have been stored");
}
});
myApp.factory('TestResource', ['$resource', function($resource) {
return $resource('test.json', {}, {} );
}]);
The problem is that the data does not get stored. Am I missing something here ? Here is a plunkr : http://plnkr.co/edit/gist:3662702