<p dir="auto"><strong>I'm submitting a ...</strong>  (check one with "x")</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="[x] feature request"><pre class="notranslate"><code class="notranslate">[x] feature request
</code></pre></div>
<p dir="auto"><strong>Current behavior</strong></p>
<p dir="auto">I have to store subscriptions and unsubscribe on destroy:</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="@Component({ /* ... */ })
export class MyComponent {
    public data;
    private dataSubscription: Subscription;

    constructor(private http: Http, private route: ActivatedRoute) {
    }

    ngOnInit() {
        this.dataSubscription = this.route.params
            .switchMap(() =&gt; this.http.get('/api'))
            .subscribe(response =&gt; this.data = response.json());
    }

    ngOnDestroy() {
        if (this.dataSubscription) {
            this.dataSubscription.unsubscribe();
        }
    }
}"><pre class="notranslate">@<span class="pl-smi">Component</span><span class="pl-kos">(</span><span class="pl-kos">{</span> <span class="pl-c">/* ... */</span> <span class="pl-kos">}</span><span class="pl-kos">)</span>
<span class="pl-k">export</span> <span class="pl-k">class</span> <span class="pl-smi">MyComponent</span> <span class="pl-kos">{</span>
    <span class="pl-k">public</span> <span class="pl-c1">data</span><span class="pl-kos">;</span>
    <span class="pl-k">private</span> <span class="pl-c1">dataSubscription</span>: <span class="pl-smi">Subscription</span><span class="pl-kos">;</span>

    <span class="pl-en">constructor</span><span class="pl-kos">(</span><span class="pl-k">private</span> <span class="pl-s1">http</span>: <span class="pl-smi">Http</span><span class="pl-kos">,</span> <span class="pl-k">private</span> <span class="pl-s1">route</span>: <span class="pl-smi">ActivatedRoute</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-kos">}</span>

    <span class="pl-en">ngOnInit</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
        <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">dataSubscription</span> <span class="pl-c1">=</span> <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">route</span><span class="pl-kos">.</span><span class="pl-c1">params</span>
            <span class="pl-kos">.</span><span class="pl-en">switchMap</span><span class="pl-kos">(</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">http</span><span class="pl-kos">.</span><span class="pl-en">get</span><span class="pl-kos">(</span><span class="pl-s">'/api'</span><span class="pl-kos">)</span><span class="pl-kos">)</span>
            <span class="pl-kos">.</span><span class="pl-en">subscribe</span><span class="pl-kos">(</span><span class="pl-s1">response</span> <span class="pl-c1">=&gt;</span> <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">data</span> <span class="pl-c1">=</span> <span class="pl-s1">response</span><span class="pl-kos">.</span><span class="pl-en">json</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-kos">}</span>

    <span class="pl-en">ngOnDestroy</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
        <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">dataSubscription</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
            <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">dataSubscription</span><span class="pl-kos">.</span><span class="pl-en">unsubscribe</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
        <span class="pl-kos">}</span>
    <span class="pl-kos">}</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto"><strong>Expected/desired behavior</strong></p>
<p dir="auto">I would rather do <code class="notranslate">observable.takeUntil(componentDestroyEmitter)....</code> like:</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="@Component({ /* ... */ })
export class MyComponent {
    public data;

    constructor(private ngDestroyEmitter: NgDestroyEmitter, private http: Http, private route: ActivatedRoute) {
    }

    ngOnInit() {
        this.route.params
            .takeUntil(this.ngDestroyEmitter)
            .switchMap(() =&gt; this.http.get('/api'))
            .subscribe(response =&gt; this.data = response.json());
    }
}"><pre class="notranslate">@<span class="pl-smi">Component</span><span class="pl-kos">(</span><span class="pl-kos">{</span> <span class="pl-c">/* ... */</span> <span class="pl-kos">}</span><span class="pl-kos">)</span>
<span class="pl-k">export</span> <span class="pl-k">class</span> <span class="pl-smi">MyComponent</span> <span class="pl-kos">{</span>
    <span class="pl-k">public</span> <span class="pl-c1">data</span><span class="pl-kos">;</span>

    <span class="pl-en">constructor</span><span class="pl-kos">(</span><span class="pl-k">private</span> <span class="pl-s1">ngDestroyEmitter</span>: <span class="pl-smi">NgDestroyEmitter</span><span class="pl-kos">,</span> <span class="pl-k">private</span> <span class="pl-s1">http</span>: <span class="pl-smi">Http</span><span class="pl-kos">,</span> <span class="pl-k">private</span> <span class="pl-s1">route</span>: <span class="pl-smi">ActivatedRoute</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-kos">}</span>

    <span class="pl-en">ngOnInit</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
        <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">route</span><span class="pl-kos">.</span><span class="pl-c1">params</span>
            <span class="pl-kos">.</span><span class="pl-en">takeUntil</span><span class="pl-kos">(</span><span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">ngDestroyEmitter</span><span class="pl-kos">)</span>
            <span class="pl-kos">.</span><span class="pl-en">switchMap</span><span class="pl-kos">(</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">http</span><span class="pl-kos">.</span><span class="pl-en">get</span><span class="pl-kos">(</span><span class="pl-s">'/api'</span><span class="pl-kos">)</span><span class="pl-kos">)</span>
            <span class="pl-kos">.</span><span class="pl-en">subscribe</span><span class="pl-kos">(</span><span class="pl-s1">response</span> <span class="pl-c1">=&gt;</span> <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">data</span> <span class="pl-c1">=</span> <span class="pl-s1">response</span><span class="pl-kos">.</span><span class="pl-en">json</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-kos">}</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto">To avoid additional Subscription state and manual cleanup code.</p>
<ul dir="auto">
<li><strong>Angular version:</strong> 2.0.0-rc.4</li>
<li><strong>Browser:</strong> [all]</li>
<li><strong>Language:</strong> [all]</li>
</ul>
<p dir="auto"><strong>I'm submitting a ...</strong></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="[ ] bug report
[x] feature request
[ ] support request"><pre class="notranslate"><code class="notranslate">[ ] bug report
[x] feature request
[ ] support request
</code></pre></div>
<p dir="auto"><strong>Current behavior</strong><br>
Currently, component lifecycle hooks are handled by implementing one or more interfaces provided by angular. I find myself often wanting to subscribe to an observable until the component/directive is destroyed. To do this, I have to have a member for each subscription for later disposal in the <code class="notranslate">ngOnDestroy()</code> method.<br>
Example:</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="/* imports */

@Directive({
  selector: '[onDrag]'
})
export class OnDrag implements OnInit, OnDestroy {
  dragStart: Subscription;
  dragEnter: Subscription;
  dragOver: Subscription;
  dragLeave: Subscription;

  constructor(private element: ElementRef) { }

  ngOnInit(): any {
    let elem = this.element.nativeElement;

    this.dragStart = Observable.fromEvent(elem, 'dragstart')
      .do(() =&gt;{ /*do stuff*/ })
      .subscribe();

    this.dragEnter = Observable.fromEvent(elem, 'dragenter')
      .do(() =&gt;{ /*do stuff*/ })
      .subscribe();

    this.dragOver = Observable.fromEvent(elem, 'dragover')
      .do(() =&gt;{ /*do stuff*/ })
      .subscribe();

    this.dragLeave = Observable.fromEvent(elem, 'dragleave')
      .do(() =&gt;{ /*do stuff*/ })
      .subscribe();

    // etc...
  }

  ngOnDestroy(): any {
    this.dragStart.unsubscribe();
    this.dragEnter.unsubscribe();
    this.dragOver.unsubscribe();
    this.dragLeave.unsubscribe();
  }
}"><pre class="notranslate"><span class="pl-c">/* imports */</span>

@<span class="pl-smi">Directive</span><span class="pl-kos">(</span><span class="pl-kos">{</span>
  <span class="pl-c1">selector</span>: <span class="pl-s">'[onDrag]'</span>
<span class="pl-kos">}</span><span class="pl-kos">)</span>
<span class="pl-k">export</span> <span class="pl-k">class</span> <span class="pl-smi">OnDrag</span> <span class="pl-k">implements</span> <span class="pl-smi">OnInit</span><span class="pl-kos">,</span> <span class="pl-smi">OnDestroy</span> <span class="pl-kos">{</span>
  <span class="pl-c1">dragStart</span>: <span class="pl-smi">Subscription</span><span class="pl-kos">;</span>
  <span class="pl-c1">dragEnter</span>: <span class="pl-smi">Subscription</span><span class="pl-kos">;</span>
  <span class="pl-c1">dragOver</span>: <span class="pl-smi">Subscription</span><span class="pl-kos">;</span>
  <span class="pl-c1">dragLeave</span>: <span class="pl-smi">Subscription</span><span class="pl-kos">;</span>

  <span class="pl-en">constructor</span><span class="pl-kos">(</span><span class="pl-k">private</span> <span class="pl-s1">element</span>: <span class="pl-smi">ElementRef</span><span class="pl-kos">)</span> <span class="pl-kos">{</span> <span class="pl-kos">}</span>

  <span class="pl-en">ngOnInit</span><span class="pl-kos">(</span><span class="pl-kos">)</span>: <span class="pl-smi">any</span> <span class="pl-kos">{</span>
    <span class="pl-k">let</span> <span class="pl-s1">elem</span> <span class="pl-c1">=</span> <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">element</span><span class="pl-kos">.</span><span class="pl-c1">nativeElement</span><span class="pl-kos">;</span>

    <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">dragStart</span> <span class="pl-c1">=</span> <span class="pl-smi">Observable</span><span class="pl-kos">.</span><span class="pl-en">fromEvent</span><span class="pl-kos">(</span><span class="pl-s1">elem</span><span class="pl-kos">,</span> <span class="pl-s">'dragstart'</span><span class="pl-kos">)</span>
      <span class="pl-kos">.</span><span class="pl-en">do</span><span class="pl-kos">(</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span><span class="pl-kos">{</span> <span class="pl-c">/*do stuff*/</span> <span class="pl-kos">}</span><span class="pl-kos">)</span>
      <span class="pl-kos">.</span><span class="pl-en">subscribe</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

    <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">dragEnter</span> <span class="pl-c1">=</span> <span class="pl-smi">Observable</span><span class="pl-kos">.</span><span class="pl-en">fromEvent</span><span class="pl-kos">(</span><span class="pl-s1">elem</span><span class="pl-kos">,</span> <span class="pl-s">'dragenter'</span><span class="pl-kos">)</span>
      <span class="pl-kos">.</span><span class="pl-en">do</span><span class="pl-kos">(</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span><span class="pl-kos">{</span> <span class="pl-c">/*do stuff*/</span> <span class="pl-kos">}</span><span class="pl-kos">)</span>
      <span class="pl-kos">.</span><span class="pl-en">subscribe</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

    <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">dragOver</span> <span class="pl-c1">=</span> <span class="pl-smi">Observable</span><span class="pl-kos">.</span><span class="pl-en">fromEvent</span><span class="pl-kos">(</span><span class="pl-s1">elem</span><span class="pl-kos">,</span> <span class="pl-s">'dragover'</span><span class="pl-kos">)</span>
      <span class="pl-kos">.</span><span class="pl-en">do</span><span class="pl-kos">(</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span><span class="pl-kos">{</span> <span class="pl-c">/*do stuff*/</span> <span class="pl-kos">}</span><span class="pl-kos">)</span>
      <span class="pl-kos">.</span><span class="pl-en">subscribe</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

    <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">dragLeave</span> <span class="pl-c1">=</span> <span class="pl-smi">Observable</span><span class="pl-kos">.</span><span class="pl-en">fromEvent</span><span class="pl-kos">(</span><span class="pl-s1">elem</span><span class="pl-kos">,</span> <span class="pl-s">'dragleave'</span><span class="pl-kos">)</span>
      <span class="pl-kos">.</span><span class="pl-en">do</span><span class="pl-kos">(</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span><span class="pl-kos">{</span> <span class="pl-c">/*do stuff*/</span> <span class="pl-kos">}</span><span class="pl-kos">)</span>
      <span class="pl-kos">.</span><span class="pl-en">subscribe</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

    <span class="pl-c">// etc...</span>
  <span class="pl-kos">}</span>

  <span class="pl-en">ngOnDestroy</span><span class="pl-kos">(</span><span class="pl-kos">)</span>: <span class="pl-smi">any</span> <span class="pl-kos">{</span>
    <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">dragStart</span><span class="pl-kos">.</span><span class="pl-en">unsubscribe</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">dragEnter</span><span class="pl-kos">.</span><span class="pl-en">unsubscribe</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">dragOver</span><span class="pl-kos">.</span><span class="pl-en">unsubscribe</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">dragLeave</span><span class="pl-kos">.</span><span class="pl-en">unsubscribe</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
  <span class="pl-kos">}</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto"><strong>Desired behavior</strong><br>
My suggestion is to provide components with an observable for each lifecycle event (via injection perhaps?). The above example could turn into something like:</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="/* imports */

@Directive({
  selector: '[onDrag]'
})
export class OnDrag implements OnInit {
  constructor(
    private element: ElementRef,
    private lifecycle: ThingWithLifecycleObservablesForThisComponent
  ) { }

  ngOnInit(): any {
    let elem = this.element.nativeElement;

    Observable.fromEvent(elem, 'dragstart')
      .do(() =&gt;{ /*do stuff*/ })
      .takeUntil(this.lifecycle.ngDestroy$)
      .subscribe();

    Observable.fromEvent(elem, 'dragenter')
      .do(() =&gt;{ /*do stuff*/ })
      .takeUntil(this.lifecycle.ngDestroy$)
      .subscribe();

    Observable.fromEvent(elem, 'dragover')
      .do(() =&gt;{ /*do stuff*/ })
      .takeUntil(this.lifecycle.ngDestroy$)
      .subscribe();

    Observable.fromEvent(elem, 'dragleave')
      .do(() =&gt;{ /*do stuff*/ })
      .takeUntil(this.lifecycle.ngDestroy$)
      .subscribe();

    // etc...
  }
}"><pre class="notranslate"><span class="pl-c">/* imports */</span>

@<span class="pl-smi">Directive</span><span class="pl-kos">(</span><span class="pl-kos">{</span>
  <span class="pl-c1">selector</span>: <span class="pl-s">'[onDrag]'</span>
<span class="pl-kos">}</span><span class="pl-kos">)</span>
<span class="pl-k">export</span> <span class="pl-k">class</span> <span class="pl-smi">OnDrag</span> <span class="pl-k">implements</span> <span class="pl-smi">OnInit</span> <span class="pl-kos">{</span>
  <span class="pl-en">constructor</span><span class="pl-kos">(</span>
    <span class="pl-k">private</span> <span class="pl-s1">element</span>: <span class="pl-smi">ElementRef</span><span class="pl-kos">,</span>
    <span class="pl-k">private</span> <span class="pl-s1">lifecycle</span>: <span class="pl-smi">ThingWithLifecycleObservablesForThisComponent</span>
  <span class="pl-kos">)</span> <span class="pl-kos">{</span> <span class="pl-kos">}</span>

  <span class="pl-en">ngOnInit</span><span class="pl-kos">(</span><span class="pl-kos">)</span>: <span class="pl-smi">any</span> <span class="pl-kos">{</span>
    <span class="pl-k">let</span> <span class="pl-s1">elem</span> <span class="pl-c1">=</span> <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">element</span><span class="pl-kos">.</span><span class="pl-c1">nativeElement</span><span class="pl-kos">;</span>

    <span class="pl-smi">Observable</span><span class="pl-kos">.</span><span class="pl-en">fromEvent</span><span class="pl-kos">(</span><span class="pl-s1">elem</span><span class="pl-kos">,</span> <span class="pl-s">'dragstart'</span><span class="pl-kos">)</span>
      <span class="pl-kos">.</span><span class="pl-en">do</span><span class="pl-kos">(</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span><span class="pl-kos">{</span> <span class="pl-c">/*do stuff*/</span> <span class="pl-kos">}</span><span class="pl-kos">)</span>
      <span class="pl-kos">.</span><span class="pl-en">takeUntil</span><span class="pl-kos">(</span><span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">lifecycle</span><span class="pl-kos">.</span><span class="pl-c1">ngDestroy$</span><span class="pl-kos">)</span>
      <span class="pl-kos">.</span><span class="pl-en">subscribe</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

    <span class="pl-smi">Observable</span><span class="pl-kos">.</span><span class="pl-en">fromEvent</span><span class="pl-kos">(</span><span class="pl-s1">elem</span><span class="pl-kos">,</span> <span class="pl-s">'dragenter'</span><span class="pl-kos">)</span>
      <span class="pl-kos">.</span><span class="pl-en">do</span><span class="pl-kos">(</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span><span class="pl-kos">{</span> <span class="pl-c">/*do stuff*/</span> <span class="pl-kos">}</span><span class="pl-kos">)</span>
      <span class="pl-kos">.</span><span class="pl-en">takeUntil</span><span class="pl-kos">(</span><span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">lifecycle</span><span class="pl-kos">.</span><span class="pl-c1">ngDestroy$</span><span class="pl-kos">)</span>
      <span class="pl-kos">.</span><span class="pl-en">subscribe</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

    <span class="pl-smi">Observable</span><span class="pl-kos">.</span><span class="pl-en">fromEvent</span><span class="pl-kos">(</span><span class="pl-s1">elem</span><span class="pl-kos">,</span> <span class="pl-s">'dragover'</span><span class="pl-kos">)</span>
      <span class="pl-kos">.</span><span class="pl-en">do</span><span class="pl-kos">(</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span><span class="pl-kos">{</span> <span class="pl-c">/*do stuff*/</span> <span class="pl-kos">}</span><span class="pl-kos">)</span>
      <span class="pl-kos">.</span><span class="pl-en">takeUntil</span><span class="pl-kos">(</span><span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">lifecycle</span><span class="pl-kos">.</span><span class="pl-c1">ngDestroy$</span><span class="pl-kos">)</span>
      <span class="pl-kos">.</span><span class="pl-en">subscribe</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

    <span class="pl-smi">Observable</span><span class="pl-kos">.</span><span class="pl-en">fromEvent</span><span class="pl-kos">(</span><span class="pl-s1">elem</span><span class="pl-kos">,</span> <span class="pl-s">'dragleave'</span><span class="pl-kos">)</span>
      <span class="pl-kos">.</span><span class="pl-en">do</span><span class="pl-kos">(</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span><span class="pl-kos">{</span> <span class="pl-c">/*do stuff*/</span> <span class="pl-kos">}</span><span class="pl-kos">)</span>
      <span class="pl-kos">.</span><span class="pl-en">takeUntil</span><span class="pl-kos">(</span><span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">lifecycle</span><span class="pl-kos">.</span><span class="pl-c1">ngDestroy$</span><span class="pl-kos">)</span>
      <span class="pl-kos">.</span><span class="pl-en">subscribe</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

    <span class="pl-c">// etc...</span>
  <span class="pl-kos">}</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto"><strong>What is the motivation / use case for changing the behavior?</strong><br>
Ultimately, I would like a way to not have to hold onto subscriptions as class members (perhaps there is a better way to achieve this than my suggestion). It could be convenient/concise to be able to handle lifecycle events as observables within components. As a workaround currently I have been extending my components with a base class that provides (some) of these events:</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import { OnInit, OnDestroy } from '@angular/core';
import { Subject } from 'rxjs/Subject';

export class ComponentLifeCycle implements OnInit, OnDestroy {
  protected ngInit$: Subject&lt;any&gt; = new Subject&lt;any&gt;();
  protected ngDestroy$: Subject&lt;any&gt; = new Subject&lt;any&gt;();

  ngOnInit(): any {
    this.ngInit$.next({});
  }

  ngOnDestroy(): any {
    this.ngDestroy$.next({});
  }
}"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-kos">{</span> <span class="pl-smi">OnInit</span><span class="pl-kos">,</span> <span class="pl-smi">OnDestroy</span> <span class="pl-kos">}</span> <span class="pl-k">from</span> <span class="pl-s">'@angular/core'</span><span class="pl-kos">;</span>
<span class="pl-k">import</span> <span class="pl-kos">{</span> <span class="pl-smi">Subject</span> <span class="pl-kos">}</span> <span class="pl-k">from</span> <span class="pl-s">'rxjs/Subject'</span><span class="pl-kos">;</span>

<span class="pl-k">export</span> <span class="pl-k">class</span> <span class="pl-smi">ComponentLifeCycle</span> <span class="pl-k">implements</span> <span class="pl-smi">OnInit</span><span class="pl-kos">,</span> <span class="pl-smi">OnDestroy</span> <span class="pl-kos">{</span>
  <span class="pl-k">protected</span> <span class="pl-c1">ngInit$</span>: <span class="pl-smi">Subject</span><span class="pl-kos">&lt;</span><span class="pl-smi">any</span><span class="pl-kos">&gt;</span> <span class="pl-c1">=</span> <span class="pl-k">new</span> <span class="pl-smi">Subject</span><span class="pl-kos">&lt;</span><span class="pl-smi">any</span><span class="pl-kos">&gt;</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
  <span class="pl-k">protected</span> <span class="pl-c1">ngDestroy$</span>: <span class="pl-smi">Subject</span><span class="pl-kos">&lt;</span><span class="pl-smi">any</span><span class="pl-kos">&gt;</span> <span class="pl-c1">=</span> <span class="pl-k">new</span> <span class="pl-smi">Subject</span><span class="pl-kos">&lt;</span><span class="pl-smi">any</span><span class="pl-kos">&gt;</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

  <span class="pl-en">ngOnInit</span><span class="pl-kos">(</span><span class="pl-kos">)</span>: <span class="pl-smi">any</span> <span class="pl-kos">{</span>
    <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">ngInit$</span><span class="pl-kos">.</span><span class="pl-en">next</span><span class="pl-kos">(</span><span class="pl-kos">{</span><span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
  <span class="pl-kos">}</span>

  <span class="pl-en">ngOnDestroy</span><span class="pl-kos">(</span><span class="pl-kos">)</span>: <span class="pl-smi">any</span> <span class="pl-kos">{</span>
    <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">ngDestroy$</span><span class="pl-kos">.</span><span class="pl-en">next</span><span class="pl-kos">(</span><span class="pl-kos">{</span><span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
  <span class="pl-kos">}</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto"><strong>Please tell us about your environment:</strong></p>
<ul dir="auto">
<li><strong>Angular version:</strong> 2.0.0-rc.4</li>
<li><strong>Browser:</strong> all</li>
<li><strong>Language:</strong> all</li>
</ul>