Trying to make an API call when loading one of my views.
controllers.controller("detailsCtrl", ["$scope", "$routeParams", "$filter", "$http", function($scope, $routeParams, $filter, $http) {
$scope.getCurrent = function(url, id, callBack, apiCall, promise) {
var url = "api.openweathermap.org/data/2.5/weather?id=2172797";
var id = "&appid=d436c04d23a5a44329eb8255190a84be";
var callBack = "&callback=JSON_CALLBACK";
var apiCall = url += id += callBack;
var promise = $http.jsonp(apiCall);
promise.success(function(response) {
$scope.current = response.current;
console.log($scope.current);
});
};
$scope.cityName = $filter("filter")($scope.data.list, {
id: $routeParams.cityId
})[0];
}]);
using ng-init in the html
<div ng-controller="detailsCtrl" ng-init="getCurrent()">
<h1>{{ cityName.name }}</h1>
<tr>
<td>lat: {{cityName.coord.lat}}, lon: {{cityName.coord.lon}}</td>
<td>{{}}</td>
<td>{{}}</td>
<td>{{}}</td>
<td>{{}}</td>
<td>Clouds: {{cityName.clouds.all}}</td>
<td>{{}}</td>
<td>{{}}</td>
</tr>
</div>
Keep getting: http://localhost:8080/api.openweathermap.org/data/2.5/weather?id=2172797&appid=d436c04d23a5a44329eb8255190a84be&callback=angular.callbacks._1 , any ideas why?
note Also making another API call in my mainview before the user navigates to the detail view. Tried ng-click when the user switches view, but it didnt make the call at all.