Angularjs push object undefined is not a function

So, I have a problem with this code, and I don't know why I get this 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     with i ( http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.18/angular.min.js:100:144 ) with 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 ) with 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{62 ) with 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 () scope. I was looking for why this is happening, but I cannot find it. I want the veilingen object to get the first 2 results, and after loading it, the user can change it with:

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

But yes, if the push doesn't work ...?

+4
source share
1 answer

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

$scope.veilingen = [];
+12
source

All Articles