未定义angularjs推的对象不是一个函数 [英] angularjs push object undefined is not a function

查看:378
本文介绍了未定义angularjs推的对象不是一个函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我有这个code一个问题,我不`吨知道为什么我得到这个错误

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:

类型错误:未定义不是一个函数
      在 http://example.com/includes/controllers/veilingCntrl.js:12: 30
      在的http:// cdnjs。 cloudflare.com/ajax/libs/angular.js/1.2.18/angular.min.js:72:72
      在我(的http:// cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.18/angular.min.js:100:144
      在我(的http:// cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.18/angular.min.js:100:144
      在的http:// cdnjs。 cloudflare.com/ajax/libs/angular.js/1.2.18/angular.min.js:101:308
      日k。$的eval( HTTP ://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.18/angular.min.js:112:32
      日k。$摘要( HTTP ://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.18/angular.min.js:109:121
      日k。$申请( HTTP ://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.18/angular.min.js:112:362
      在H(的http:// cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.18/angular.min.js:72:327
      在x(的http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.18/angular.min.js:77:288)

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)

12号线是推()区域。我已搜查为什么发生这种情况,但我不能老是找到它。我要的是对象veilingen获取第2的结果及其负载后,用户可以改变它:

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

推荐答案

$ scope.veilingen 被声明为对象而不是数组。

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

$scope.veilingen = [];

这篇关于未定义angularjs推的对象不是一个函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆