Angularjs 角度等待Meteor调用返回值
我试图在Meteor.call成功返回数据后,在我的模板上显示Meteor.call的结果。当模板加载时,它不会显示任何数据,因为ClientsList中的构造函数已经结束,但它内部的meteor调用仍在运行(异步) 模板(clientsList.html):Angularjs 角度等待Meteor调用返回值,angularjs,meteor,angular-meteor,Angularjs,Meteor,Angular Meteor,我试图在Meteor.call成功返回数据后,在我的模板上显示Meteor.call的结果。当模板加载时,它不会显示任何数据,因为ClientsList中的构造函数已经结束,但它内部的meteor调用仍在运行(异步) 模板(clientsList.html): {{client.Name} 如何使我的模板在显示之前等待ClientsList中的构造函数完全接收值“this.clients” 提前感谢您的帮助。我知道,ctor是进行异步调用的糟糕地方。ctor的目的是简单地构造对象,而不
-
{{client.Name}
如何使我的模板在显示之前等待ClientsList中的构造函数完全接收值“this.clients”
提前感谢您的帮助。我知道,ctor是进行异步调用的糟糕地方。ctor的目的是简单地构造对象,而不是以后使用它所需的一切。你不能强迫它等待。您需要使用订阅和助手方法来处理它
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
})
}
<ul>
<li ng-repeat="client in clientsList.clients">
{{client.Name}}
</li>
</ul>