1

我对使用 Meteor + angular + ionic 构建的移动应用程序有一个奇怪的问题。

在其中一个选项卡上,我订阅了调用的集合Contacts并在列表中显示联系人ionic列表:

<ion-list>
    <ion-item ng-repeat="contact in contacts" type="item-text-wrap">
        <strong>{{contact.name}}</strong>
    </ion-item>
</ion-list>

这是此选项卡的控制器中的内容:

$scope.contacts = $meteor.collection( Contacts );

这就是我在router设置中的内容:

...
} ).state( 'tab.contacts', {
    url    : '/contacts',
    views  : {
        'tab-contacts': {
            templateUrl: 'templates/contacts/list.ng.html',
            controller : 'ContactsCtrl'
        }
    },
    resolve: {
        contacts: ['$meteor', function ( $meteor ) {
            return $meteor.subscribe( 'contacts' );
        }]
    }
} )

问题是,几乎 10 次中有 8 次在我打开我的应用程序时呈现列表 html 元素但name所有其他联系人详细信息都是空的,如附图所示。它只是一个列表项,但联系人本身是未定义的:

空的联系人列表

空项目的数量与联系人的数量相匹配,但该列表中的每个联系人都是空的,未定义的。我尝试了所有可能的技巧以使其正确渲染,但失败了。正在呈现的联系人数量是 90,所以它根本不是一个大列表。

如果我使用 chrome usb 检查器刷新我的应用程序页面,它会正确呈现。我错过了什么?

4

1 回答 1

0

试试这个:

resolve: {
    "contacts": ['$meteor', function ( $meteor ) {
        $meteor.subscribe( 'contacts' ).then(function(subscriptionHandle){
            return $meteor.collection( Contacts );
        })
    }]
}

而且您现在不需要在控制器中使用$scope.contacts = $meteor.collection( Contacts );此控制器控制器需要如下所示:app.controller( "myCtrl", function( $scope, contacts ) { code... }

$scope.contacts 将像这样返回集合。

希望它有效。

于 2015-11-09T14:50:47.240 回答