I have my controller and it fetches data from 2 json files using $http service. This data is stored inside $scope variables like $scope.name and $scope.application. But I am unable to parse over both these variables inside the same controller.
The commented portion of the code throws me error "Cannot read property 'length' of undefined as it cannot find these two variables.
Can some one please help me solve this?
var phonecatControllers = angular.module('phonecatControllers', []);
phonecatControllers.controller('PhoneListCtrl',['$scope', '$http','$log', function ($scope, $http,$log)
{
$http.get('server/user/details.json').success
(function(data)
{
$scope.users = data;
/*$scope.users = data.splice(0, n);*/ //Restricts to 'n' users
for (var i = 0; i < $scope.users.length; i++)
{
$log.info($scope.users[i].name);
}
}
);
$http.get('server/user/software/application.json').success
(function(data)
{
$scope.applications = data;
/*$scope.users = data.splice(0, n);*/ //Restricts to 'n' users
for (var i = 0; i < $scope.applications.length; i++)
{
$log.info($scope.applications[i].application);
}
}
);
/*for (var i = 0; i < $scope.users.length; i++)
{
for (var j = 0; j < $scope.applications.length; j++)
{
if($scope.users[i].application === $scope.applications[j].application)
{
$log.info($scope.users[i].application );
$log.info($scope.applications[i].application);
}
}
}*/
}
]
);