angular4获得焦点事件,Angular 4在onBlur(focusOut)中获取输入值(时间选择器)

I have two time fields but I can't get their values to compare them. All I get is undefined! I want to get the value as soon as the field is left (focusout).

Here is my .ts code:

isMeridian = false;

showSpinners = false;

timeStart: any;

timeSegment: any;

onKeyTime(event) {

console.log("onKeyTime :" + this.mySummaryForm.value.startTime);

this.timeStart = this.mySummaryForm.value.startTime; //event.target.value;

console.log("select+++startTime : " + this.timeStart);

console.log("change+++segTime : " + this.timeSegment);

}

onKeySeg(event) {

console.log("onKeySeg : " + this.mySummaryForm.value.segmentTime3);

this.timeSegment = this.mySummaryForm.value.segmentTime3;

console.log("select---startTime : " + this.timeStart);

console.log("change---segTime : " + this.timeSegment);

}

checkTimeValue() {

console.log("checkTimeValue :");

if((this.timeSegment < this.timeStart)) {

console.log("a : " + this.timeSegment + " > " + this.startTime);

// alert("good choice!");

}

else {

console.log("b : " + this.startTime + " < " + this.timeSegment);

// alert("time segment should be later than start time.");

}

}

Here is my .html code:

Start time : {{mySummaryForm.value.startTime |date: 'shortTime' | json}}

Segment time : {{mySummaryForm.value.segmentTime3 |date: 'shortTime' | json}}

解决方案

What I endup doing :

my .ts code

onChangeStart(event, label) {

console.log("EVENT : " + event);

if (label == 'start_time') {

this.timeStart = event;

}

}

onChangeSeg(event, label, index) {

if (label == 'segmentTime3') {

this.timeSegment = event;

console.log("this.timeSegment : " + this.timeSegment);

}

if (this.timeSegment > this.timeStart) {

console.log(this.timeSegment + " > " +this.timeStart);

}

else {

console.log(this.timeSegment + " < " +this.timeStart);

alert("the segment time is wrong ! The segment time should be later than the start time. ");

}

}

my .html code

Start time :

Segment time :

There might be a better option but this works for me.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值