I'm doing some interfaces with AngularJS and watching the Chrome Console I detect that each http request to an API it makes for duplicate. Is there any way to avoid this?
This is my simplified code
$http.jsonp('http://APIURL.com/api/category/menu?callback=JSON_CALLBACK').success(function(data){
$scope.categories=data.categories;
});
Full code:
var kbControllers = angular.module('kbControllers', []);
kbControllers.controller("KBHomeController", function ($scope, $http, $rootScope) {
$rootScope.header = 'Title of page';
$http.jsonp('apicall.com/api/category/menu?callback=JSON_CALLBACK').success(function (data) {
$scope.categories = data.categories;
});
});
and this is my console

any thought?
console.log()message to all of the places where your $http functions are being called. It's been my experience that when I find the spot that calls a $http function more than once I just need to modify that spot's condition that triggers the $http function. The code you posted is perfect, the flow you take that calls that code is what usually is the issue.