Struggling to perform an API call when loading a specific view.
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];
}]);
utilizing ng-init within 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>
Continuously receiving: http://localhost:8080/api.openweathermap.org/data/2.5/weather?id=2172797&appid=d436c04d23a5a44329eb8255190a84be&callback=angular.callbacks._1 , any insights on why?
note Additionally attempting another API call in the mainview prior to the user navigating to the detailed view. Tried using ng-click when transitioning views, but it did not trigger the call at all.