Good day.

I have a list of students where Fio is displayed. I want to highlight a certain person, where I can then change his name. How to bind <input> to a specific person?

<li ng-repeat="Student in Students"> <a ng-href="#">{{Student.Fio}}</a> </li> 

And there is a field Phio <input> .

I want to bind it to the selected student, or rather to the controller, so that you can track the change in value and send new data to the server.

How to do this? Thank.

  • @ Roman Rakzin, If you are given an exhaustive answer, mark it as correct (click on the check mark next to the selected answer). - Nicolas Chabanovsky

1 answer 1

 <input ng-model="Student.Fio" type="text"/> 

Changes to the input field will be displayed in the model. The main thing in the controller is to determine the model itself.

About change tracking:

 <input ng-model="Student.Fio" ng-change="sendDataToServer()" type="text"/> 

In js:

 $scope.sendDataToServer = function () { $http.post('/path', { students: $scope.Students // передаете свою модель, на сервере парсите данные }).success(function (resp) { // logic }); }; 

In the case of PHP, for example, I take the data on the server like this:

 $post = json_decode(file_get_contents('php://input'), true); //просто $_POST приходит пустым