0

Hi i am trying to figure out,Whether am receiving the data from api or not.Is there anyway to check it?I am totally new to angular.js. My code:

<html ng-app>
<head>
   <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.8/angular.min.js"></script>
   <meta charset="utf-8">
   <meta http-equiv="Content-Type" content="text/html">
   <title>API Webapp using AngularJS - Not So Clever Demo</title>
   <link rel="stylesheet" type="text/css" media="all" href="css/styles.css">
</head>

<body ng-controller="GitHubCtrl">

  <p>{{user.results}}<p>;



<script>
   function GitHubCtrl($scope, $http) {
      $scope.getGitInfo = function () {
         $scope.userNotFound = false;
         $scope.loaded = false;

         $http.get("https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=-33.8670522,151.1957362&radius=500&types=food&name=cruise&key=MY_KEY")
      .success(function (data) {
         $scope.user = data;
         console.log(data);
         $scope.loaded = true;
      })
               .error(function () {
                  $scope.userNotFound = true;
               });

      }
   }
</script>

Please correct me if i did some mistakes.And help me to get this work.I tried using alert to view the data but i was not able to get it.

1
  • I'd like to see the bit where you are calling $scope.getGitInfo method Commented Jun 26, 2014 at 11:26

3 Answers 3

1

There is a plugin for Chrome called Batarang which should helps you. Please see here: https://chrome.google.com/webstore/detail/angularjs-batarang/ighdmehidhipcmcojjgiloacoafjmpfk?hl=en

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

Comments

0

You can just do the below in your html page:-

<pre>{{user}}</pre>

This will show the whole user object that is being returned.

Another thing is that, you are doing everything inside getGitInfo method on $scope, but it is never called, so user information will never get populated anyways.

Apart from this, there are lots of other minor issues with your code. If you submit a jsFiddle/plunker, I or someone else will be able to explain and correct them for you.

3 Comments

Have a look at jsfiddle.net/jain208/TFDY5/8. I have tried to replicate your code. It doesn't work because I got an error message saying that the api key is invalid. You can sort that out, but the general code would be the same.
Another thing is that typically you would put your http calls in a separate service and not inside your controller.
Thanks but i am just now starting
0

Please find the below code

<script>
           function GitHubCtrl($scope, $http) {
               console.log('hello')
              //$scope.getGitInfo = function () {
                 $scope.userNotFound = false;
                 $scope.loaded = false;

                 $http.jsonp("https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=-33.8670522,151.1957362&radius=500&types=food&name=cruise&key=MY_KEY" + $scope.username)
              .success(function (data) {
                 $scope.user = data;
                 console.log(data);
                 $scope.loaded = true;
              })
                       .error(function () {
                          $scope.userNotFound = true;
                       });

              //}
           }
        </script>

Error which throws from the external link:


"error_message" : "The provided API key is invalid.",

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.