So I have created a SPA that displays student information from a database. I have function to add a student, display student data with specific views and update/delete student records.
I am struggling with the update function. My issue is that when I type a student ID into the search box on the page I cannot get it to pull that specific record from the JSON response from the server. I just can't seem to find the logic to write this correctly.
Here is part of my code, sorry if I have struggled to explain this properly. I could not find any other articles relating specifically to this issue I am having.
Here is the function I am using that is attached to the button on my HTML page, currently I just have it setup to pull the first record in the array (just to prove it will pull the data and fill the fields.
app.controller('editCtrl', function($scope, $http) {
$http.get("getStudentData.php")
.then(function (response) {
$scope.students = response.data;
});
$scope.getRecord = function() {
id = $scope.sid;
$scope.student = $scope.students[0];
And here is part of my HTML:
<div class="form-group">
<label for="sid">Student ID:</label>
<input type="text" class="form-control" id="sid" ng-model="sid">
</div>
<p><button type="button" class="btn btn-primary" ng-click="getRecord()">Get
Student Info</button> </p>
<div class='row'>
<div class="col-md-6">
<div class="form-group">
<label for="first_name">First Name:</label>
<input type="text" class="form-control" id="first_name" ng-
model="student.first_name">
</div>
<div class="form-group">
<label for="last_name">Last Name:</label>
<input type="text" class="form-control" id="last_name" ng-
model="student.last_name">