I'm really struggling with my AngularJS controller (and I think my controller is just as confused by my code). My issue is that I have groups and users, where the user can select a group. However, I'm having trouble accessing the SelectedClass in the user object. The console keeps telling me it's undefined, even though I've already defined it at the top of the controller like this:
$scope.SelectedClass = {};
Here's an excerpt from my controller:
$scope.SelectedClass = {};
$http.get('/groups').then(function(result){
console.log(result);
$scope.groups = result.data;
$scope.SelectedClass = $scope.groups[0];
$scope.changed = function() {
console.log($scope.SelectedClass);
}
});
$http.get('/users').then(function(result){
console.log(result);
$scope.allusers = {};
$scope.allusers = result.data;
console.log($scope.SelectedClass.group_id);
});
Can anyone offer guidance on what might be going wrong here? Any help would be greatly appreciated!