路线变化的奇怪行为

时间:2015-10-02 06:46:03

标签: meteor angular-meteor

我在收集订阅中遇到奇怪的流星行为。我有一个抽象路线邮箱,下面有三条路线。收件箱,已发送和单一邮件(显示两个邮件的详细信息)。现在的问题是,当我在单个邮件路由中解析邮件集合时,它绑定了收件箱和发送的相同邮件集合,尽管我们为两者发布了不同的集合。 注意:它工作正常,直到我从两个单一邮件路线。例如,当我点击收件箱中的任何邮件或发送邮件时,它将转到单一邮件路线并显示电子邮件的详细信息。什么时候回来从这里开始问题。它为两者订阅邮件集合。即如果inbox有6并且发送有3则两者都显示9。我试过几个小时但没有运气。  任何帮助是极大的赞赏 !  我正在粘贴很多代码来解决我的确切问题。这是服务器中的mail.js

Meteor.publish("mails", function (obj) {

    //Will use for admin
    isAuth(this);

    var query = {identity:this.userId};
    if (obj) {
        query[obj.condition] = obj.id;
    }
    return Mails.find(query);

});

Meteor.publish("mailsTo", function (options) {
    //if user not logged in
    isAuth(this);
    Counts.publish(this, 'countOfNewMails', Mails.find({identity: this.userId, 'to.id': this.userId, unread: true}));
    Counts.publish(this, 'countOfToMails', Mails.find({identity: this.userId, 'to.id': this.userId}), { noReady: true });
    return Mails.find({identity: this.userId, 'to.id': this.userId}, options);
});

Meteor.publish("mailsFrom", function (options) {
    //if user not logged in
    isAuth(this);
    Counts.publish(this, 'countOfFromMails', Mails.find({identity: this.userId, from: this.userId}), { noReady: true });
    return Mails.find({identity: this.userId, from: this.userId}, options);
});

这是我的route.js

angular.module('Secret')
    .config(['$urlRouterProvider', '$stateProvider', '$locationProvider',
        function($urlRouterProvider, $stateProvider, $locationProvider){

            $locationProvider.html5Mode(true);

            $stateProvider
                .state('home', {
                    url: '/home',
                    templateUrl: 'client/home/views/home.ng.html',
                    controller: 'homeCtrl'
                })
                .state('login', {
                    url: '/homes/:id/login',
                    templateUrl: 'client/login/views/login.ng.html',
                    controller: 'loginCtrl'
                })
                .state('signup', {
                    url: '/homes/:id/signup',
                    templateUrl: 'client/signup/views/signup.ng.html',
                    controller: 'signupCtrl'
                })
                .state('forgotPassword', {
                    url: '/homes/:id/forgot-password',
                    templateUrl: 'client/forgotPassword/views/forgotPassword.ng.html',
                    controller: 'forgotPasswordCtrl'
                })
                .state('profile', {
                    url: '/profile',
                    templateUrl: 'client/profile/views/profile.ng.html',
                    controller: 'profile'
                })
                .state('mailbox', {
                    url: '/mailbox',
                    templateUrl: 'client/mailBox/views/mailbox.ng.html',
                    controller: 'mailboxCtrl',
                    abstract: true
                })
                .state('mailbox.inbox', {
                    url: '/inbox',
                    templateUrl: 'client/inbox/views/inbox.ng.html',
                    controller: 'inboxCtrl',
                    resolve: {
                        "currentUser": ["$meteor", function($meteor){
                            return $meteor.requireUser();
                        }]
                    }
                })
                .state('mailbox.sent', {
                    url: '/sent',
                    templateUrl: 'client/sent/views/sent.ng.html',
                    controller: 'sentCtrl'
                })
                .state('mailbox.singleMail', {
                    url: '/:folder/:id',
                    params: {
                        hasnext: null
                    },
                    templateUrl: 'client/singleMail/views/single.ng.html',
                    controller: 'singleCtrl',
                    resolve: {
                        "currentUser": ["$meteor", function($meteor){
                            return $meteor.requireUser();
                        }],
                        statesSub: ['$meteor', '$stateParams', function($meteor, $stateParams) {
                            return $meteor.subscribe('mails', $stateParams.id);
                        }]
                    }
                })
                .state('mailbox.compose', {
                    url: '/compose/:r/:mailId',
                    templateUrl: 'client/compose/views/compose.ng.html',
                    controller: 'composeCtrl'
                })

            $urlRouterProvider.otherwise("/home");

        }])
    .run(['$rootScope', '$state',
        function($rootScope, $state){
        $rootScope.$on("$stateChangeError", function(event, next, previous, error) {
            // We can catch the error thrown when the $requireUser promise is rejected
            // and redirect the user back to the main page
            //if (error === "AUTH_REQUIRED") {
                $state.go("home");
            //}
        });
    }]);

并在控制器中作为简单的SentCtrl

$scope.page = 1;
        $scope.perPage = 50;
        $scope.sort = { createdAt: -1 };

        //get reactively
        $meteor.autorun($scope, function() {
            $scope.mails = $scope.$meteorCollection(Mails).subscribe('mailsFrom',{
                limit: parseInt($scope.getReactively('perPage')),
                skip: (parseInt($scope.getReactively('page')) - 1) * parseInt($scope.getReactively('perPage')),
                sort: $scope.getReactively('sort')
            })
        })

InboxCtrl

$scope.page = 1;
    $scope.perPage = 50;
    $scope.sort = { createdAt: -1 };

    $scope.pagechanged = function(sign){
        sign ? $scope.page++ : $scope.page--;
    }

    //get reactively
    $meteor.autorun($scope, function() {
        $scope.inbox = $scope.$meteorCollection(Mails).subscribe('mailsTo',{
            limit: parseInt($scope.getReactively('perPage')),
            skip: (parseInt($scope.getReactively('page')) - 1) * parseInt($scope.getReactively('perPage')),
            sort: $scope.getReactively('sort')
        })
    })

在单邮件中我只是通过params获取邮件

$scope.currentMail = $meteor.object(Mails, $stateParams.id);

1 个答案:

答案 0 :(得分:4)

  

每当您订阅一个集合时,您都会获得订阅句柄   为了这。因此,您可以在模板销毁时停止它。 (即   流星角度为subscription_handle.stop())的{​​{1}}   上下文。