我正在使用Meteor + AngularJS框架。如何确保流星本地采集已准备好前路由
我想根据存储在脱机集合中的数据(使用ground:db)来控制路由,但脱机数据在路由之前不能保证准备就绪。
如果集合不处于脱机状态,似乎有一些方法(如“waitOn”或“subscriptionReady”值得研究,但脱机集合不需要订阅或发布,我如何确保它们在路由之前或之前已做好准备该应用程序是自举的?
主要来源片段:
1.route.js
import { LastLogin } from '../lib/collections';
angular.module('app')
.config(function ($stateProvider, $urlRouterProvider) {
console.log(LastLogin.find().count());
if(LastLogin.find().count() > 0){
$urlRouterProvider.otherwise('main/homepage');
}else{
$urlRouterProvider.otherwise('login');
}
});
2.collections.js
export const LastLogin = new Ground.Collection('lastLogin', {connection: null});
在大多数的情况下,LastLogin.find()计数( )为0,很少会是1,事实上lastLogin集合中有几条记录可以在登录页面显示后正确打印出来,这对我来说已经太迟了。
我试图通过Tracker.autorun
包围下面的代码Tracker.autorun(function(){
if(LastLogin.find().count() > 0){
$urlRouterProvider.otherwise('main/home');
}else{
$urlRouterProvider.otherwise('login');
}
});
,但没有帮助。
我的最终目的是让上次用户自动登录,即使在离线状态下也是如此。有更好的解决方案