0

I am trying to pull data from external domain using angularjs. I dont see any issue in the console. I tried to my best and fiddled here. Any help or pointer would be great.

Vie Code

<div ng-controller="myCtrl">{{response}}
    <button ng-click="getData()">GET Request</button>
</div>

Controller code

angular.module('myApp', [])
    .controller('myCtrl', function ($scope, $http) {
    $scope.getData = function () {
        $http.get("http://api.openweathermap.org/data/2.5/weather?zip=98007,us").success(function (response) {
            $scope.myData = response;
            console.log(response)
        });
    };
});
1

4 Answers 4

2

Your code is fine but you are missing a few things in your markup. You are missing ng-app and you should be doing {{myData}} and not {{response}} (because myData is bound to your scope and assigned to response, there is not variable named response bound to your scope). See plunker

  <body ng-app="myApp">
    <div ng-controller="myCtrl">{{myData}}
        <button ng-click="getData()">GET Request</button>
    </div>
  </body>
Sign up to request clarification or add additional context in comments.

1 Comment

Actually the syntax might be wrong.
1

Just add ng-app in body or html

By looking at your jsFiddle is clear that your issues is that you are not adding the app name in your html.

Here is your update jsFiddle : http://jsfiddle.net/kn4yaoco/3/

you can see in console that your request is giving response properly.

Comments

1

Using the browser dev tools what does the the network tab show ? Was the request successful, was the request even made ?

Comments

0

You should .then with $http, so something like:

$http.get("http://api.openweathermap.org/data/2.5/weather?zip=98007,us")
  .then(function(response) {
     console.log(response);
  }):

Best

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.