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)
        });
    };
});
Kurkula
  • 6,386
  • 27
  • 127
  • 202
  • you have to pass parameters seperatly. check http://stackoverflow.com/questions/13760070/angularjs-passing-data-to-http-get-request – terafor Aug 29 '15 at 04:29

4 Answers4

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>
logee
  • 5,017
  • 1
  • 26
  • 34
  • Actually the syntax [might](https://docs.angularjs.org/api/ng/service/$http#deprecation-notice) be wrong. – skubski Aug 29 '15 at 05:24
1

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

zayquan
  • 7,544
  • 2
  • 30
  • 39
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.

maddygoround
  • 2,145
  • 2
  • 20
  • 32
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

R.A. Lucas
  • 1,121
  • 1
  • 12
  • 17