I'm new to angularJS. What I need to do is to add an employee into a file named as "employees.json" where an employee has 3 features, name, city and state which can be entered through text boxes. My current code is below and due to some reason it is not working. Can someone help me?
$scope.addEmplyee=function(){
/ create new employee here with user inputs
// an Employee object has three properties: name, city, state
var name=$scope.name;
var city=$scope.city;
var state=$scope.state;
$http.get('employees.json').success(function (data){
$scope.employees = data});
$scope.employee={"name":name,"city":city,"state":state};
$http.post('/employees.json', {"employee": $scope.employee})
.success(function(response, status, headers, config){
$scope.employees.push($scope.employee);
});
};
HTML code is as follows
<div>
<b>Add Employee :</b>
<div>Name:<input type="text" ng-model="name"/></div>
<div>City: <input type="text" ng-model="city"/></div>
<div>State: <input type="text" ng-model="state"/></div>
<button class="btn" ng-click="addEmplyee()">Add</button>
</div>