M
M
mr_drinkens892014-09-12 17:42:49
Angular
mr_drinkens89, 2014-09-12 17:42:49

How to collect all fields in angular.js?

Let me know who is facing it.
I understand angular.js, before that I only worked with jquery.
The essence is this: there is a block in which there are 2 selects and 3 checkboxes. When changing any input (be it a select, or a checker), an Ajax request with these parameters should leave.
I rendered the elements like this:

<select name="inspection" ng-change="change()" ng-model="formData.inspection">

And checkboxes
<input type="checkbox" 
      ng-model="formData.power1" 
      ng-change="change()"  
      ng-true-value={{ p.pk }}
      ng-checked="true"

So, the checkers are all marked, but they are not included in the object. After changing the checker or select, the object is filled with the required fields.
jquery has a serialize() method that iterates over the entire form and generates the selected options.
Is there a similar equivalent in angular.js?
It is clear that you can manually select each value in the controller and assign it to the request object. But this is a jquery-way, but I want to somehow optimize everything. To click on the select, and all fields are automatically assigned to the object.
Thank you

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Kir, 2014-09-12
@angry_bender

Try ng-change="change(formData)" like this.

A
agladkov, 2014-10-30
@agladkov

Hang $watch on formData:

$scope.$watch('formData', function () {
            // submit $scope.formData;
        }, true);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question