I'm fairly new to AngularJS so apologies in advance.
var tcores = 0;
angular.module('core').controller('HomeController', ['$scope', '$http',
function($scope, $http) {
$http.get('search?idc=LH5&type=Virtual&cluster=1').success(function(data) {
$scope.servers = data; // get data from json
angular.forEach($scope.servers, function(item){
//console.log(item.cores);
if(parseInt(item.cores) != "NaN" && item.cores != "") {
if(angular.isNumber(parseInt(item.cores))) {
tcores = parseInt(tcores) + parseInt(item.cores);
}
}
})
console.log("Hall 5. Cluster 1 Total Cores: " + tcores);
});
}
]);
angular.module('core').controller('HomeController', ['$scope', '$http',
function($scope, $http) {
$http.get('search?idc=LH5&type=Virtual&cluster=2').success(function(data2) {
$scope.serverscluster = data2; // get data from json
angular.forEach($scope.serverscluster, function(item){
//console.log(item.cores);
if(parseInt(item.cores) != "NaN" && item.cores != "") {
if(angular.isNumber(parseInt(item.cores))) {
tcores = parseInt(tcores) + parseInt(item.cores);
}
}
})
console.log("Hall 5. Cluster 2 Total Cores: " + tcores);
});
}
]);
I'm trying to run both functions (both are pointed at different JSON outputs), however I am only receiving a response for "cluster 2".
Please advise how I can run both functions in the same module, ideally I will be running 8 of these requests on the same page so advice is most appreciated.#
Can you also tell my why only the bottom function is executing?
Thank you very much!
$http.getin a unique controller name.