From 3104c3cafbc4b7263cd29deac82ef900db43af54 Mon Sep 17 00:00:00 2001 From: George Kalpakas Date: Fri, 25 Sep 2020 01:30:57 +0300 Subject: [PATCH] fixup! TEMP - Enable AOT always --- .../src/app/countdown-parent.component.ts | 13 +++---------- .../src/app/countdown-timer.component.ts | 9 ++++----- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/aio/content/examples/component-interaction/src/app/countdown-parent.component.ts b/aio/content/examples/component-interaction/src/app/countdown-parent.component.ts index 5c2399d72182fe..193884b5b075e0 100644 --- a/aio/content/examples/component-interaction/src/app/countdown-parent.component.ts +++ b/aio/content/examples/component-interaction/src/app/countdown-parent.component.ts @@ -1,6 +1,6 @@ // #docplaster // #docregion vc -import { AfterViewInit, ViewChild } from '@angular/core'; +import { ViewChild } from '@angular/core'; // #docregion lv import { Component } from '@angular/core'; import { CountdownTimerComponent } from './countdown-timer.component'; @@ -37,19 +37,12 @@ export class CountdownLocalVarParentComponent { } `, styleUrls: ['../assets/demo.css'] }) -export class CountdownViewChildParentComponent implements AfterViewInit { +export class CountdownViewChildParentComponent { @ViewChild(CountdownTimerComponent) private timerComponent: CountdownTimerComponent; - seconds() { return 0; } - - ngAfterViewInit() { - // Redefine `seconds()` to get from the `CountdownTimerComponent.seconds` ... - // but wait a tick first to avoid one-time devMode - // unidirectional-data-flow-violation error - setTimeout(() => this.seconds = () => this.timerComponent.seconds, 0); - } + seconds() { return this.timerComponent?.seconds ?? 0; } start() { this.timerComponent.start(); } stop() { this.timerComponent.stop(); } diff --git a/aio/content/examples/component-interaction/src/app/countdown-timer.component.ts b/aio/content/examples/component-interaction/src/app/countdown-timer.component.ts index dcc88334d0201e..cba4de07ac42a7 100644 --- a/aio/content/examples/component-interaction/src/app/countdown-timer.component.ts +++ b/aio/content/examples/component-interaction/src/app/countdown-timer.component.ts @@ -1,19 +1,16 @@ // #docregion -import { Component, OnDestroy, OnInit } from '@angular/core'; +import { Component, OnDestroy } from '@angular/core'; @Component({ selector: 'app-countdown-timer', template: '

{{message}}

' }) -export class CountdownTimerComponent implements OnInit, OnDestroy { +export class CountdownTimerComponent implements OnDestroy { intervalId = 0; message = ''; seconds = 11; - clearTimer() { clearInterval(this.intervalId); } - - ngOnInit() { this.start(); } ngOnDestroy() { this.clearTimer(); } start() { this.countDown(); } @@ -22,6 +19,8 @@ export class CountdownTimerComponent implements OnInit, OnDestroy { this.message = `Holding at T-${this.seconds} seconds`; } + private clearTimer() { clearInterval(this.intervalId); } + private countDown() { this.clearTimer(); this.intervalId = window.setInterval(() => {