From 574a2ae46f7f9cb9e2b9b2b599e379a20be349c5 Mon Sep 17 00:00:00 2001 From: insanity Date: Tue, 29 May 2018 15:16:06 +0900 Subject: [PATCH] test --- .../component/selector/selector.component.ts | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) 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) {