$http.get() response properties undefined


#1

I have a controller that is getting a JSON file and returning a response of an array [ {users: [ {name: “someName”, department: “someDepartment”},…] } ]
When I iterate over the ‘department’ property it is coming up undefined even though I can see it using console.log($scope.users[i].department); What is going on?

var app = angular.module('facultyDirectory', ['angularUtils.directives.dirPagination', 'ui.bootstrap']);

app.controller('facultyListing', function($scope, $http){
    $http.get(jsonFeed).success(function(response){ 
        // JSON Data	
        $scope.users = response[0].users;
        // var users = response[0].users;
        for(var i = 0;$scope.users.length; i++) {
            console.log($scope.users[i].department);
           if($scope.users[i].department.indexOf('&') != -1){
               var newDepts = $scope.users[i].department.split('&');
            var userDepartment1 = newDepts[0];
            var userDepartment2 = newDepts[1];
            } 
        }
});

#2

Try it with


for(var i = 0; i<$scope.users.length ; i++)

#3

Thanks Leon! That corrected the issue, but It also led me to a great revelation! Angular filter method will look for any string that matches within the selected property, so I didn’t even have to split the string on the comma for it to work! Thanks again!