angular.js icon indicating copy to clipboard operation
angular.js copied to clipboard

$http inside a custom directive not working in 1.1.5 but working in 1.0.7 jsfiddle attached

Open phillycoder opened this issue 13 years ago • 3 comments

1.1.5 >> http://jsfiddle.net/GwK9C/1/ 1.0.7 >> http://jsfiddle.net/GwK9C/2/

Any suggestions? Thanks

phillycoder avatar Jun 13 '13 01:06 phillycoder

:+1:

var User = $resource('/user/:userId', {userId:'@id'});
User.save({param: value});

save every second time (sent first and second requests at the same time) if values were different and save after any other action (user.$save() f.e.) if values were identical. Queries arbitrarily added to any queue.

tamtakoe avatar Jun 13 '13 03:06 tamtakoe

@phillycoder 1.1.x branch introduces promise-based request interceptors for $http and as a result now $http request must be triggered from within $digest loop. In short - you need to wrap your $http call into $apply the same way as you would do for other operations that need to kick off AngularJS-specific processing.

Here is a working jsFiddle: http://jsfiddle.net/PSMKN/1/

pkozlowski-opensource avatar Jun 15 '13 12:06 pkozlowski-opensource

@pkozlowski-opensource thanks a lot, one question, is this only when i use $http inside directive? because my $http.get calls works fine in a controller.

Thanks again!!

phillycoder avatar Jun 18 '13 18:06 phillycoder