5

So, I have a problem with this code and I don`t know why I get that error

$scope.veilingen = {};
$http.get('./helpers/get/Veilingen.php').
success(function(data) {
    if(debugMode) console.log(data);
    $scope.veilingenCache = data;
    for(var i = 0; i < 2; i++) {
        console.log($scope.veilingen)
        $scope.veilingen.push({
           test: 'hello'
        });
        console.log($scope.veilingen)
    }
});

I get this error:

TypeError: undefined is not a function at http://example.com/includes/controllers/veilingCntrl.js:12:30 at http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.18/angular.min.js:72:72 at I (http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.18/angular.min.js:100:144) at I (http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.18/angular.min.js:100:144) at http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.18/angular.min.js:101:308 at k.$eval (http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.18/angular.min.js:112:32) at k.$digest (http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.18/angular.min.js:109:121) at k.$apply (http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.18/angular.min.js:112:362) at h (http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.18/angular.min.js:72:327) at x (http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.18/angular.min.js:77:288)

Line 12 is the push() area. I have searched why this happens but I can`t find it. What I want is that the object veilingen gets the first 2 results and after its load the user can change it with:

$scope.setLimitVeiling = function(items) {
    for(var i = 0; i < items; i++) {
        $scope.veilingen.push($scope.veilingenCache[i]);
    }
}

But yeah, if push is not working...?

2
  • have you declared $scope.veilingen as an array ?? Commented Aug 11, 2014 at 10:07
  • objects don't have a push() method. Arrays have. It should be $scope.veilingen = []; Commented Aug 11, 2014 at 10:08

1 Answer 1

13

$scope.veilingen is declared as an object instead of array.

$scope.veilingen = [];
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.