Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

angularjs push object undefined is not a function

Tags:

angularjs

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...?

like image 892
DazDylz Avatar asked Aug 11 '14 10:08

DazDylz


1 Answers

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

$scope.veilingen = [];
like image 89
msapkal Avatar answered Sep 23 '22 00:09

msapkal