Created
February 14, 2020 16:06
-
-
Save akatakritos/acf26036f105e9657cb069ce7b5a924d to your computer and use it in GitHub Desktop.
angular.js rxjs misc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** AngularJS function to unsubscribe from observables when scope destroyed. | |
* @param $scope - Scope that is listening to an observable. | |
*/ | |
export function registerDestroyedObservable($scope: any) { | |
if($scope.destroyed$) { | |
return; | |
} | |
$scope.destroyed$ = new Subject(); | |
$scope.$on('$destroy', () => { | |
$scope.destroyed$.next(); | |
$scope.destroyed$.complete(); | |
}); | |
} | |
export function takeUntilScopeDestroyed<T>($scope: any) { | |
registerDestroyedObservable($scope); | |
return takeUntil<T>($scope.destroyed$); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment