Angular-MeteorとIonicを使用しています。イオンビューを変更した後のメテオの定期購読は停止していません
流星バージョン:1.3.2.4
、角度バージョン:1.5.5
、イオンバージョン:1.2.4
。
また、私の流星/角型アプリにもES2015を使用しています。
import angular from 'angular';
import angularMeteor from 'angular-meteor';
import uiRouter from 'angular-ui-router';
import { Meteor } from 'meteor/meteor';
import { SomeCollection } from 'path/to/collection';
import './view1.html';
class View1 {
constructor($scope, $reactive, $state) {
this.$state = $state;
this.$scope = $scope;
$reactive(this).attach($scope);
this.subscribe('my.subscription');
this.helpers({
list:() => {
return SomeCollection.find({});
}
});
}
}
export default angular.module('view1', [
angularMeteor,
uiRouter,
View1
]).config(config);
function config($stateProvider) {
'ngInject';
$stateProvider.state('app.view1', {
url: '/view1',
template: '<view-1></view-1>',
views: {
'appContent': {
controller: View1,
controllerAs: 'view1',
templateUrl: 'path/to/template.html'
}
}
});
}
そして私は、私は別のパブリケーションにサブスクライブしてる除き、セットアップの類似したタイプを持っている他のビュー:私は一つのビューのために
。
ような何か:
import angular from 'angular';
import angularMeteor from 'angular-meteor';
import uiRouter from 'angular-ui-router';
import { Meteor } from 'meteor/meteor';
import { SomeOtherCollection } from 'path/to/other/collection';
import './view2.html';
class View2 {
constructor($scope, $reactive, $state) {
this.$state = $state;
this.$scope = $scope;
$reactive(this).attach($scope);
this.subscribe('my.other.subscription');
this.helpers({
list:() => {
return SomeOtherCollection.find({});
}
});
}
}
export default angular.module('view2', [
angularMeteor,
uiRouter,
View2
]).config(config);
function config($stateProvider) {
'ngInject';
$stateProvider.state('app.view2', {
url: '/view2',
template: '<view-2></view-2>',
views: {
'appContent': {
controller: View2,
controllerAs: 'view2',
templateUrl: 'path/to/other/template.html'
}
}
});
}
私は、私はまだ前のビューからサブスクリプションからのポーリングだと気づい私のイオンのビューを切り替えます。ドキュメントによると、$scope
を使用すると、stop()
関数を自動的に呼び出す必要があります。
しかし、Mongolを使用すると、サブスクリプションがビューを切り替えることで停止していないことがわかります。
私は現在、クイックフィックスを使用することができましたが、それは私が必要ではないはずと信じての回避策と私のコードを移入するために醜いと力だ、すなわちやっ:私は間違って
$scope.$on('$ionicView.enter',() => {
this.subscriptions = [];
this.subscriptions.push(this.subscribe('some.collection'));
this.subscriptions.push(this.subscribe('some.other.collection'));
});
$scope.$on('$ionicView.leave',() => {
for (var sub in this.subscriptions) {
this.subscriptions[sub].stop();
}
});
何をしているのですか?どのようにIonicビューを切り替えるときにサブスクリプションを適切に停止するのですか?
あなたの「回避策」は実際には正しいパターンだと思います... –