为什么ng-repeat只返回MongoDB结果中的一个对象?

时间:2016-12-29 03:40:14

标签: angularjs json node.js model-view-controller angularjs-ng-repeat

在试图回答this question时,我决定将问题分解为更简单的问题。

问题:如果我使用ng-repeat为" test"中的每个元素创建行,我会得到一行包含一个大型JSON对象。

HTML

cqlsh:test> INSERT into qw (id, user, pass, email, phoneNum) VALUES (1,  'scman', '123','sc@gmaail.com','123-456-7890');
NoHostAvailable:

产生的JSON

this is a HTML table where there should be more than one row with each object but there is only 1

test.js (clientApp.controller:TestCtrl)

<div ng-view class="ng-scope">
    <table>
        <thead>
            <th>JSON for each object</th>
        </thead>
        <tbody>
            <tr ng-repeat="X in test">
                <td>{{ X }}</td>
            </tr>
        </tbody>
    </table>
</div>

app.js

'use strict';
angular.module('clientApp')
  .controller('TestCtrl', function (Test) {
    this.test = Test.getList().$object;
});

总结:应该有更多的行,每个JSON对象一个我的测试数据库,但我得到一个大的JSON blob。

更新 @therobinkim建议我在ng.learn&#34;中将ng-repeat查询更改为&#34; X,它提供了以下有趣的Restangular JSON内容: enter image description here

2 个答案:

答案 0 :(得分:1)

<tr ng-repeat="X in test.test">...</tr>

第一个test来自controllerAs代码中的$routerProvider

第二个test来自this.test代码中的TestCtrl

更新$object中的this.test = Test.getList().$object;对于此格式非常重要。或者,您可以使用Promises。 https://github.com/mgonto/restangular#enhanced-promises

答案 1 :(得分:0)

您的测试服务在哪里?尝试删除$ object

'use strict';
   angular.module('clientApp')
     .controller('TestCtrl', function (Test) {
        //this.learn = Test.getList().$object;
    this.learn = Test.getList();
 });
相关问题