Skip to content

Commit c6d751e

Browse files
committed
($scope.subscribe): Adding to the tutorial
1 parent 5a3bb92 commit c6d751e

File tree

1 file changed

+4
-24
lines changed

1 file changed

+4
-24
lines changed

.docs/angular-meteor/client/views/steps/tutorial.step_12.tpl

+4-24
Original file line numberDiff line numberDiff line change
@@ -421,40 +421,20 @@ There is only one problem in our app right now - if you will go into the party d
421421
422422
The reason is that we are calling a different subscription on the same collection inside the partyDetails controller..
423423
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.
425425
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.
435427
436428
First remove to subscription from $meteor.object:
437429
438430
$scope.party = $meteor.object(Parties, $stateParams.partyId);
439431
440-
And now add the subscribe function and save the handle somewhere:
432+
And now add the subscribe function:
441433
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');
453435
454436
That's it.
455437
456-
Maybe in the future we will add an automatic way to open and close subscriptions in scope's load and destroy events.
457-
458438
459439
# Summary
460440

0 commit comments

Comments
 (0)