I encountered an issue while attempting to add records to a JSON file using AngularJS. I suspect there might be an error in my code.
Can someone provide guidance on the correct way to achieve this task?
Here is a link to my sample code on Plunker: Plunker Sample Code
myApp.controller('ToddlerCtrl', function ($scope,$http) {
$http.get('taskList.json').success(function (data){
$scope.tasks = data;
});
$scope.addEmp = function(){
$scope.bla="sijs";
$scope.tasks.push({ task:$scope.empName, priority:$scope.empCity, status:$scope.empState });
var dataObj = {
task : $scope.empName,
priority : $scope.empCity,
status:$scope.empState
};
var res = $http.post('taskList.json', dataObj);
res.success(function(data, status, headers, config) {
$scope.message = data;
});
res.error(function(data, status, headers, config) {
alert( "failure message: " + JSON.stringify({data: data}));
});
}
});