I have created a controller and a service in AngularJS. I am trying to pull some json data from a URL and display it on the web page. Following are the main parts of the code.
Controller
app.controller('MainController',function ($scope,myservice) {
$scope.getsomedata = function () {
$scope.somedata = myservice.getdata();
}
});
Service
app.factory('myservice', ['$http', function ($http) {
var serviceObj = {};
serviceObj.get = $http.get('https://s3.amazonaws.com/codecademy-content/courses/ltp4/forecast-api/forecast.json').then(function (resp) {
return resp.data;
});
serviceObj.getdata = function () {
return serviceObj.get;
};
return serviceObj;
}])
mywebpage.html
<body ng-app="myApp">
<div class="wrapper" ng-controller="MainController">
<a ng-href='#here' ng-click='getsomedata()'>click me</a>
{{somedata}}
</div>
When I execute the html page, I see {}. I cannot see any data. I want to understand what am I doing wrong here.
(I have not put the code for MyApp here).