http - AngularJS 1.1.5 $resource.get is not creating XHR request from setTimeout -


i have asked question on google forum angularjs , haven't heard until now. can me understand going on here?

i trying periodically refresh resource , doesn't seem working. have tracked until fact promise has been obtained $http service xhr request never created , fired when method invoked in settimeout. however, if same without settimeout seems working fine.

working jsfiddle: http://jsfiddle.net/hponnu/z62qn/2/

window.root_module = angular.module("myapp", ['ngresource']); function maincontroller($scope, $resource) {     $scope.buttonclick = function () {         var res = $resource("http://www.google.com");         res.get({}, function (response) {             alert("response");         }, function (err) {             alert("error");         });     } } 

broken jsfiddle: http://jsfiddle.net/hponnu/h8aet/10/

window.root_module = angular.module("myapp", ['ngresource']); window.count = 0; function maincontroller($scope, $resource) {     $scope.buttonclick = function () {        settimeout(function () {             alert("timeout: " + window.count);             var res = $resource("http://www.google.com");             res.get({},                 function (response) {                     alert("response: " + window.count);                     window.count++;                 }, function (err) {                     alert("error: " + window.count);                     window.count++;                 });        }, 1000);     } 

}

as see in broken jsfiddle error alert not fired first request unless click event triggered click on button again. have started noticing angularjs 1.1.4

any ideas/suggestions?

ps: https://groups.google.com/forum/#!topic/angular/t28mazamt0e link google groups thread.

you should use angularjs's $timeout instead of settimeout().

function maincontroller($scope, $resource, $timeout) {     $scope.buttonclick = function () {         $timeout(function () {             ...         }, 1000);     } } 

Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -