在我的角度应用程序中重复不重复

时间:2015-02-06 05:53:03

标签: angularjs

我有一个数组,但它只显示$ scope.stocks [0]

{{stocks[0]}} // returns something
{{stocks[1]}} // returns another thing
{{stocks[2]}} // returns one more thing
{{stocks[3]}} // and so on...
{{stocks[4]}}
{{stocks[5]}}
<div ng-repeat="stock in stocks">
    {{stock}}  // only repeats one time. Returns stock[0]
</div>

这是一些额外的代码:

    window.google = {
        visualization: {
            Query: {
                setResponse: function (a) {
                        $scope.stocks = Array;
                    for (var i = 0; i < a.table.rows.length; i = i + 1){
                        $scope.stocks[i] = a.table.rows[i].c;
                        console.log(a.table.rows[i].c);
                        console.log($scope.stocks[i]);

                    }
                    console.log('Stocks are',$scope.stocks);
                }
            }
        }
    };

这是一些控制台日志

stocks.js:22 [Object, Object]
stocks.js:23 [Object, Object]
stocks.js:19 hi2
stocks.js:22 [Object, Object]
stocks.js:23 [Object, Object]
stocks.js:19 hi2
stocks.js:22 [Object, Object]
stocks.js:23 [Object, Object]
stocks.js:19 hi2
stocks.js:22 [Object, Object]
stocks.js:23 [Object, Object]
stocks.js:26 Stocks are function Array() { [native code] }

1 个答案:

答案 0 :(得分:1)

尝试

$scope.stocks = new Array() 

反对

$scope.stock = Array

这是因为你将函数绑定到你的股票而不是数组对象