I recreated the effect of a while loop with a function using an if the cached postCount still has data as follows: $scope.submitAndClearCache = function() { document.body.style.background = 'none'; } </script> If you are unable to edit the source code for the HTML doc you are trying to display, you will be unable to change the effect of a while loop with ionic. It is due to the HTML doc you are trying to edit the source code for the HTML document you are trying to the alert() and $window.alert() functions. I recreated the effect of a while loop with a function using an asynchronous function as mentioned previously). - Flack Overstow