1

I made a GET request to get a user by ID, but it doesn't seem to work (nothing happens at all). I am using my user ID so I know the user exists. I get no error message.

Here is my AngularJS code :

myApp.controller('mainpage', ['$scope', '$http', '$resource', 'AuthService', 'sharedPropertie', function ($scope, $http, $resource, AuthService, sharedPropertie) {

$scope.test='7194489';
$scope.user=[];

 $http.get('https://api.stackexchange.com/2.2/users/'+$scope.test+'?order=desc&sort=reputation&site=stackoverflow')
  .then(function(value) {
    console.log('value in mainpage'+value);
       $scope.user.push(value);
      });
}]);

And my view:

<body>
  <div ng-controller="meetupsController">
  <div ng-controller="routeController">
           <a ng-click='gotoprive()' class="btn btn-default">Prive</a>
           <a ng-click='gotopublicforum()' class="btn btn-default">Forum public</a>
           <a ng-click='logout()' class="btn btn-default">logout</a>
           <a ng-click='topublicforumgw()' class="btn btn-default">public forum</a>
           <a ng-click='toprivateforumgw()' class="btn btn-default">private forum</a>
           <a ng-click='toaccesscontrol()' class="btn btn-default">accesscontrol</a>
           <a ng-click='tomessengergw()' class="btn btn-default">messenger</a>
           <a ng-click='topopulatedforumgw()' class="btn btn-default">populated forum</a>
         </div>
    <h1>{{user[0]}}</h1>
  </div>
</body>
7
  • Does it not log anything? If not, change it to .then(console.log, console.log) and see what happens. Commented Dec 3, 2016 at 18:31
  • 1
    hey 10x for your comment. It doesnt log anything. where should i pput .then(console.log, console.log) Commented Dec 3, 2016 at 18:34
  • After $http.get, where you currently have the .then - just replace that with my suggestion and see what gets logged. Commented Dec 3, 2016 at 18:35
  • nothing gets displayed @Aurora0001 Commented Dec 3, 2016 at 18:38
  • 1
    You were right i didnt use the right ctrler in my view post you answer so i can accep it @Aurora0001 10q Commented Dec 3, 2016 at 18:48

1 Answer 1

1

You are using the wrong controller, so your controller's code (including the $http.get) never gets executed in the first place. Change <div ng-controller="meetupsController"> to <div ng-controller="mainpage"> so the mainpage controller's code gets executed.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.