M
M
Maxim2015-02-15 19:02:54
JavaScript
Maxim, 2015-02-15 19:02:54

Angularjs: how to defeat repeated calls when using $watchCollection?

Hello !
There is a large form, with elements dependent on each other. When changing form values, you need to send a request to receive a response from the server.

$scope.form = {};

$scope.$watchCollection('form', function(form){                       
       if ( ! form.brandId && form.modelId){
            delete form.modelId;    
       }                      
      console.log('load data ...');
});

And there is a problem in the $watch itself, if you need to delete the value of the model when the brand is selected, then the function will be called again, because the observed object has changed. And because of this situation, there are extra requests to the server.
Can you please tell me how to work with a lot of dependent elements so as not to allow repeated calls to $watchCollection ?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Dedukhin, 2015-02-16
@Demetros

Maybe something like underscore throttle?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question