Also, you have to understand how an async request works. params is empty
because the request is not completed. params will only be available once
the success function is called AFTER the request is successful. Like I
previously said - you'll have to do a bit of research and spend some time
learning how promises and async requests work.
Good luck!
On Friday, 25 April 2014 16:14:39 UTC+1, Gabriel Aszalos wrote:
>
> What you are looking for is `promises`. $http returns a promise which you
> can chain on to. Just look into the guide for the $q service and watch some
> clips on chaining promises (on egghead.io for example). Its a very
> elegant way of doing what you want and I'm sure you'll find it very useful.
>
> On Friday, 25 April 2014 16:12:03 UTC+1, Charlie Camus wrote:
>>
>> Hi all,
>>
>> I'm a beginner with Angular JS, and I think I missed something.
>>
>> Here is my code :
>>
>> $scope.listAccueil=function(){
>>
>> $http.get('/findParams')
>> .success(function(data){
>> $scope.params=data;
>> })
>>
>> console.log($scope.params); // here $scope.params is empty even
>> when '/findParams' bring something
>>
>> $http.get('/listHabitats')
>> .success(function(data){
>> $scope.listHabitats =[];
>> for (var habitat in data) {
>> if(habitat.prix>$scope.params.budget){
>> habitat.color='list-group-item-danger';
>> habitat.alert='Budget dépassé';
>> }
>> $scope.listHabitats.push(habitat);
>> }
>> })
>> }
>>
>> So my problem is, I use $scope.params in the second http call and at that
>> time it is empty. I don't understand why ! listAccueil is in a controller,
>> and the $scope variable is global to all the controller isn't it ?
>>
>> Thank you
>>
>
--
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.