Hi,
I want to update a row in html table using webApi and angular js
I have created a table employee and add to the application using entity frame work's Databasefirst method
this is code for html
<div ng-app="myApp">
<div ng-controller="myCtrl" ng-init="GetAllData()">
<p>List Of Employees</p>
<table class="table table-bordered table-hover">
<thead class="thed-dark"> <tr><th scope="col">ID</th><th>FirstName</th><th>LastName</th><th>Company</th><th>Actions</th></tr></thead>
<tr ng-repeat="Emp in employees">
<td>{{Emp.Id}}</td>
<td>{{Emp.FirstName}}</td>
<td>{{Emp.LastName}}</td>
<td>{{Emp.Company}}</td>
<td>
<input type="button" class="btn btn-warning" value="Update" ng-click="UpdateEmp(Emp)" />
</td>
</tr>
</table>
<table>
<tr><td><label class="col-md-4 control-label">FirstName:</label></td><td><input type="text" class="form-control" placeholder="FirstName" ng-model="FirstName"></td></tr>
<tr><td><label class="col-md-4 control-label">LaststName:</label></td><td><input type="text" class="form-control" placeholder="FirstName" ng-model="LastName"></td></tr>
<tr><td><label class="col-md-4 control-label">Company:</label></td><td><input type="text" class="form-control" id="inputEmail" placeholder="Company" ng-model="Company"></td></tr>
<tr><td><input type="button" id="btnSave" class="form-control btn-space" value="Submit" ng-click="UpdateData(Emp)" /></td></tr>
</table>
</div>
</div>
code for displays in html table,display row in textboxes and code for updating
<script src="~/Scripts/angular.min.js"></script>
<script >
var app = angular.module("myApp", []);
app.controller("myCtrl", function ($scope, $http) {
$scope.GetAllData = function () {
$http.get('/api/employee').then(function (response) {
$scope.employees = response.data
}, function (status) {
alert(status);
});
}
$scope.UpdateEmp = function (Emp) {
$scope.FirstName = Emp.FirstName;
$scope.LastName = Emp.LastName;
$scope.Company = Emp.Company;
}
$scope.UpdateData = function (Emp) {
Emp.FirstName = $scope.FirstName;
Emp.LastName = $scope.LastName;
Emp.Company = $scope.Company;
alert(Emp.FirstName);
$http.put('/api/Employee',Emp).then(function () {
alert("success");
})
}
});
</script>
problem is code for updating is not working
how to solve this
regards
Baiju