@@ -421,40 +421,20 @@ There is only one problem in our app right now - if you will go into the party d
421
421
422
422
The reason is that we are calling a different subscription on the same collection inside the partyDetails controller..
423
423
424
- So to fix that, we will have to close that subscription after leaving the controller.
424
+ So to fix that, we will have to close that subscription after the partyDetails controller is destroyed .
425
425
426
- First thing, we need to catch the event of the controller closing by adding the $scope .$on (' $destroy' ):
427
-
428
- $scope .$on (' $destroy' , function() {
429
-
430
- } );
431
-
432
- Now we need to get the subscription handle which will be used later to stop the subscription.
433
-
434
- We will need to call the $meteor.subscribe it self instead of the shortcut we are using right now.
426
+ Web can do that be calling $scope .subscribe method. it will automatically close the subscription when the scope gets destroyed.
435
427
436
428
First remove to subscription from $meteor .object:
437
429
438
430
$scope .party = $meteor .object(Parties, $stateParams .partyId);
439
431
440
- And now add the subscribe function and save the handle somewhere :
432
+ And now add the subscribe function:
441
433
442
- var subscriptionHandle;
443
-
444
- $meteor.subscribe('parties').then(function(handle) {
445
- subscriptionHandle = handle;
446
- } );
447
-
448
- And last thing, stop the subscription when the scope is destroyed:
449
-
450
- $scope.$on('$destroy', function() {
451
- subscriptionHandle.stop();
452
- } );
434
+ $scope .subscribe(' parties' );
453
435
454
436
That' s it.
455
437
456
- Maybe in the future we will add an automatic way to open and close subscriptions in scope's load and destroy events.
457
-
458
438
459
439
# Summary
460
440
0 commit comments