Angular等待Meteor调用返回一个值

时间:2017-01-16 17:28:07

标签: angularjs meteor angular-meteor

一旦调用成功返回数据,我试图在我的模板上显示Meteor.call的结果。当模板加载时,它不会显示任何数据,因为ClientsList中的构造函数已到达终点,但其内部的meteor调用仍在运行(异步)。

Client side code (clientsList.js):

import template from './clientsList.html';
import {Meteor} from 'meteor/meteor';

class ClientsList {
    constructor() {
        Meteor.call('getClients', function (error, response) {
            if (error) {
                // If our API returned an error, we'd see it in the console.
                console.log(error);
            } else {
                console.log(response);
                this.clients = response;
            }
        });
        console.log('End of constructor');
    }   
}

const name = 'clientsList';

export default angular.module(name, [
    angularMeteor
]).component(name, {
    template,
    controllerAs: name,
    controller: ClientsList
})
}

模板(clientsList.html):

<ul>
        <li ng-repeat="client in clientsList.clients">
                {{client.Name}}

        </li>
    </ul>

如何让我的模板等待ClientsList中的构造函数完全接收值&#34; this.clients&#34;在展示它们之前。

提前感谢您的帮助。

0 个答案:

没有答案
相关问题