As a newcomer to Angular, I am facing an issue in my mini project. The main goal of the project is to display data from a database. I have successfully set up the view to show current data by making API calls and connecting to the database. However, I am now trying to figure out how to update the data in the database when a button is clicked. I'm unsure of what kind of function I should write in my controller for this task.
var app = angular.module('myApp', ['ngResource']);
app.controller('myCtrl', function ($scope, $resource, $http, $routeParams, $location) {
var Users = $resource('/api/tables');
$scope.users = Users.query(function () {
//console.log(user);
});
});
In my (API) Tables1Controller.cs file, here is the main method:
public string GetTables()
{
JavaScriptSerializer jss = new JavaScriptSerializer();
return jss.Serialize(db.Tables);
}
And in my Index file where the data is displayed, I have added a button:
<table class="table">
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Surname</th>
<th>Address</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="user in users">
<td>{{user.Id}}</td>
<td>{{user.Name}}</td>
<td>{{user.Surename}}</td>
<td>{{user.Address}}</td>
</tr>
</tbody>
</table>
<div ng-repeat=>
{{ user.Name }}
a
</div>
<div class="btn btn-danger">Button</div>
In _Layout.cshtml, I have added ng-app and ng-controller to the body tag. I believe using ng-click near the button could be a starting point, but I'm unfamiliar with how to write the function to handle the update process.