Hi Piotr!

The $http.get is async. You can output the text you got in the response 
function (where you are setting $scope.txt, no idea why you set it to i). 
What happens in your case is:

iterate over the first element (forEach, i = 1), log scope.text as defined 
(0), make an http-call, repeat this.
Long after the loop is finished you set the $scope.text to i - an $http 
request takes longer than a few CPU cycles ;)

So, put the console.log in the line below $scope.text = i and it should do 
what you want (as long as the $http requests come back in the same order).

Kind regards,
Anton

Am Montag, 3. August 2015 21:24:16 UTC+2 schrieb Piotr L:
>
> Hi, 
>
> Could you tell me how can i resolve my problem. I would like to see i my 
> console something like this: 1,2,3. My code shows 3 x zero. 
>
> var app = angular.module('myApp', []);
>
> app.controller('mainCtrl', function ($scope, $http, $q) {
>         $scope.text = 0;
>
>         $scope.addText = function () {
>             $scope.arr = [1, 2, 3];
>
>             //var deferred = $q.defer();
>
>             $scope.arr.forEach(function (i) {
>
>                 console.log($scope.text); //0,0,0 how make to 1,2,3 ??
>                 
> $http.get('http://api.openweathermap.org/data/2.5/weather?q=London,uk').
>                     then(function (response) {
>                         $scope.text = i;
>                     }, function (response) {
>                     });
>             })
>
>
>         }
>
>
>     }
> );
>
>
>
> Thanks in advance.
>

-- 
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/d/optout.

Reply via email to