I think you've answered your own question, when saying that you shouldn't have the $http request in the filter.
The watching (result of the digest) works by comparing values, and often checks them multiple times, depending on whether it things things have 'settled'. If you spawn off a http request each time it is checked, then yes, you will cause a lot of requests. You should be only watching values which exist, or WILL exist when the promise returns. Maybe just set a variable for whether your request has been sent or not. At worst, give it a timeout, to throttle the 'updates' if you want it periodically updating. On 28 January 2014 13:09, Ismael Kafeltz <[email protected]> wrote: > The following code is spam me thousands repeated $http request until the > browser stop working. > > My only clue is something related to $digest. > > I'm using v1.2.4. > > // filter.js > (function (ng, app) > { > "use strict"; > > app.filter("Cidade", ["cidadeService", "$log", "$http", function > (cidadeService, $log, $http) > { > return function (input) > { > var promise = $http > ({ > method: "GET", > cache : true, > url: window.API_HOST + "/api/Cidades/" + input > }); > > return 'test'; > }; > }]); > > })(window.angular, window.app) > > // some index.html > <p>Cidade: {{ instituicao.Endereco.Cidade.Id | Cidade }}</p> > > This is very simple to reproduce. > > ps: i know this is not a good practice to put a service inside a filter, > does not make sense, it's like a view to know businesses rules from > controller. But this code is quick & dirty solution will soon > be refactored. (and this code is not originated mine) > > > -- > You received this message because you are subscribed to the Google Groups > "AngularJS" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/angular. > For more options, visit https://groups.google.com/groups/opt_out. > -- Tony Polinelli -- You received this message because you are subscribed to the Google Groups "AngularJS" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/angular. For more options, visit https://groups.google.com/groups/opt_out.
