From 823950b936e5b4d23e0e9fb4368bc892bce51af4 Mon Sep 17 00:00:00 2001 From: Ward Bell Date: Mon, 22 Feb 2016 02:40:57 -0800 Subject: [PATCH] docs(cookbook/component-communication): clear interval timer in OnDestroy --- .../ts/app/countdown-timer.component.ts | 24 +++++++++++-------- public/docs/ts/latest/cookbook/_data.json | 2 +- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/public/docs/_examples/cb-component-communication/ts/app/countdown-timer.component.ts b/public/docs/_examples/cb-component-communication/ts/app/countdown-timer.component.ts index aedbbf5906..0175993303 100644 --- a/public/docs/_examples/cb-component-communication/ts/app/countdown-timer.component.ts +++ b/public/docs/_examples/cb-component-communication/ts/app/countdown-timer.component.ts @@ -1,18 +1,29 @@ // #docregion -import {Component, EventEmitter, OnInit, Output} from 'angular2/core'; +import {Component, OnInit, OnDestroy} from 'angular2/core'; @Component({ selector:'countdown-timer', template: '

{{message}}

' }) -export class CountdownTimerComponent implements OnInit { +export class CountdownTimerComponent implements OnInit, OnDestroy { intervalId = 0; message = ''; seconds = 11; + clearTimer() {clearInterval(this.intervalId);} + + ngOnInit() { this.start(); } + ngOnDestroy() { this.clearTimer(); } + + start() { this._countDown(); } + stop() { + this.clearTimer(); + this.message = `Holding at T-${this.seconds} seconds`; + } + private _countDown() { - clearInterval(this.intervalId); + this.clearTimer(); this.intervalId = setInterval(()=>{ this.seconds -= 1; if (this.seconds == 0) { @@ -23,11 +34,4 @@ export class CountdownTimerComponent implements OnInit { } }, 1000); } - - ngOnInit() { this.start(); } - start() { this._countDown(); } - stop() { - clearInterval(this.intervalId); - this.message = `Holding at T-${this.seconds} seconds`; - } } \ No newline at end of file diff --git a/public/docs/ts/latest/cookbook/_data.json b/public/docs/ts/latest/cookbook/_data.json index eff6f5f019..5ee951914b 100644 --- a/public/docs/ts/latest/cookbook/_data.json +++ b/public/docs/ts/latest/cookbook/_data.json @@ -2,7 +2,7 @@ "_listtype": "alpha", "index": { - "title": "Cookbooks" + "title": "Cookbook" }, "component-communication": {