diff --git a/@overflow/probe/component/selector/selector.component.ts b/@overflow/probe/component/selector/selector.component.ts index 25fdb1e..a018727 100644 --- a/@overflow/probe/component/selector/selector.component.ts +++ b/@overflow/probe/component/selector/selector.component.ts @@ -1,11 +1,11 @@ -import { Component, Input, Output, EventEmitter, OnChanges, SimpleChanges, OnInit } from '@angular/core'; +import { Component, Input, Output, EventEmitter, OnChanges, SimpleChanges } from '@angular/core'; import { ProbeHost, Probe } from '@overflow/commons-typescript/model/probe'; @Component({ selector: 'of-probe-selector', templateUrl: './selector.component.html', }) -export class ProbeSelectorComponent implements OnInit, OnChanges { +export class ProbeSelectorComponent implements OnChanges { @Output() select = new EventEmitter(); @Input() probeHosts: ProbeHost[]; @@ -16,24 +16,22 @@ export class ProbeSelectorComponent implements OnInit, OnChanges { constructor() { } - ngOnInit() { - } - ngOnChanges(changes: SimpleChanges): void { + this.checkPreselected(); this.options = []; for (const ph of this.probeHosts) { this.options.push(ph.probe); } - - if (changes['probeHosts'] !== null && changes['probeHosts'].currentValue.length > 0) { - this.checkPreselected(); - } } checkPreselected() { - alert(this.probeHosts.length); - const preselected: ProbeHost = this.probeHosts.find(probeHost => probeHost.id === this.probeHostID); - this.select.emit(preselected); + if (!this.probeHosts || !this.probeHostID) { + return; + } + setTimeout(() => { + const preselected = this.probeHosts.find(probeHost => probeHost.id === Number(this.probeHostID)); + this.select.emit(preselected); + }); } onSelect(probe: Probe) {