import { AfterContentInit, Component, Input, EventEmitter, Output, OnChanges, SimpleChanges } from '@angular/core'; import { Anim } from './animation'; @Component({ selector: 'of-discovery-result', templateUrl: './search-result.component.html', animations: Anim }) export class SearchResultComponent implements OnChanges { @Output() stop = new EventEmitter(); @Input() started: boolean; tempData = []; tempTimer; constructor( ) { } ngOnChanges(changes: SimpleChanges): void { if (changes['started'] && changes['started'].currentValue) { this.tempTimer = setInterval(() => { this.tempFunc(); }, 1000); } } onStop() { this.stop.emit(); clearInterval(this.tempTimer); } tempFunc() { this.tempData.push({ name: 'aaa' }); } }