{"id":246,"date":"2021-01-18T08:35:59","date_gmt":"2021-01-18T07:35:59","guid":{"rendered":"http:\/\/blog.c-hase.de\/?p=246"},"modified":"2021-01-18T10:03:01","modified_gmt":"2021-01-18T09:03:01","slug":"takeuntil-subject-angular-11-not-avaivable","status":"publish","type":"post","link":"http:\/\/blog.c-hase.de\/?p=246","title":{"rendered":"takeUntil &#8211; IntervalObservable, Subject angular 11 not avaivable"},"content":{"rendered":"<p><a href=\"https:\/\/stackoverflow.com\/questions\/42490265\/rxjs-takeuntil-angular-components-ngondestroy\">https:\/\/stackoverflow.com\/questions\/42490265\/rxjs-takeuntil-angular-components-ngondestroy<\/a><\/p>\n<div class=\"js-accepted-answer-indicator grid--cell fc-green-500 py6 mtn8\" tabindex=\"0\" title=\"Loading when this answer was accepted\u2026\" role=\"note\" data-s-tooltip-placement=\"right\" aria-label=\"Accepted\">\n<div class=\"ta-center\"><\/div>\n<\/div>\n<div class=\"s-prose js-post-body\">\n<p>You could leverage a <code>ReplaySubject<\/code> for that:<\/p>\n<p><strong>EDIT:<\/strong> Different since RxJS 6.x: Note the use of the <code>pipe()<\/code> method.<\/p>\n<pre><code>class myComponent {\r\n  private destroyed$: ReplaySubject&lt;boolean&gt; = new ReplaySubject(1);\r\n\r\n  constructor(\r\n    private serviceA: ServiceA,\r\n    private serviceB: ServiceB,\r\n    private serviceC: ServiceC) {}\r\n\r\n  ngOnInit() {\r\n    this.serviceA\r\n      .pipe(takeUntil(this.destroyed$))\r\n      .subscribe(...);\r\n    this.serviceB\r\n      .pipe(takeUntil(this.destroyed$))\r\n      .subscribe(...);\r\n    this.serviceC\r\n      .pipe(takeUntil(this.destroyed$))\r\n      .subscribe(...);\r\n  }\r\n\r\n  ngOnDestroy() {\r\n    this.destroyed$.next(true);\r\n    this.destroyed$.complete();\r\n  }\r\n}<\/code><\/pre>\n<pre>let timer = IntervalObservable.create(60000);\r\nthis.subscription = timer.subscribe(\r\n\r\n=======&gt;\r\nimport {interval} from 'rxjs';\r\nimport {takeWhile} from 'rxjs\/operators';\r\n....\r\ninterval(60000).pipe(takeWhile(()=&gt;this.alive).subscribe(<\/pre>\n<p><a href=\"https:\/\/stackoverflow.com\/questions\/51688768\/migration-from-rxjs-5-to-6-intervalobservable\">https:\/\/stackoverflow.com\/questions\/51688768\/migration-from-rxjs-5-to-6-intervalobservable<\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>https:\/\/stackoverflow.com\/questions\/42490265\/rxjs-takeuntil-angular-components-ngondestroy You could leverage a ReplaySubject for that: EDIT: Different since RxJS 6.x: Note the use of the pipe() method. class myComponent { private destroyed$: ReplaySubject&lt;boolean&gt; = new ReplaySubject(1); constructor( private serviceA: ServiceA, private serviceB: ServiceB, private serviceC: ServiceC) {} &hellip; <a href=\"http:\/\/blog.c-hase.de\/?p=246\">Weiterlesen <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-246","post","type-post","status-publish","format-standard","hentry","category-angularjs-2"],"_links":{"self":[{"href":"http:\/\/blog.c-hase.de\/index.php?rest_route=\/wp\/v2\/posts\/246","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/blog.c-hase.de\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.c-hase.de\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.c-hase.de\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.c-hase.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=246"}],"version-history":[{"count":3,"href":"http:\/\/blog.c-hase.de\/index.php?rest_route=\/wp\/v2\/posts\/246\/revisions"}],"predecessor-version":[{"id":249,"href":"http:\/\/blog.c-hase.de\/index.php?rest_route=\/wp\/v2\/posts\/246\/revisions\/249"}],"wp:attachment":[{"href":"http:\/\/blog.c-hase.de\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=246"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.c-hase.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=246"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.c-hase.de\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=246"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}