[英]Angular2 - Binding of datepicker
How do I get the chosen date of input and put the tag <p>
. 如何获得所选的输入日期并放置标签
<p>
。
I'm using the jqueryUI datepicker, already I tried to do the binding trying to capture with the change and click events, but did not work. 我正在使用jqueryUI datepicker,已经尝试进行绑定以尝试捕获change和click事件,但是没有用。
Can anybody help me? 有谁能够帮助我?
import "rxjs/Rx";
import {Component, AfterViewInit} from '@angular/core';
declare var $: any;
@Component({
selector: '<my-evento></my-evento>',
template: `<input (change)="updateDate($event)" type="text" id="datepicker">
<p>{{ date }}</p>`
})
export class EventoComponent implements AfterViewInit{
date: string;
constructor(){}
ngAfterViewInit() {
$(function() {
$("#datepicker").datepicker();
});
}
updateDate($event): void {
this.date = $event.target.value;
}
}
when you bind the model like this: 当您像这样绑定模型时:
<input [(ngModel)]="date" type="date" id="datepicker">
does the compiler tell you that the format has to be in yyyy-dd-mm format? 编译器告诉您格式必须为yyyy-dd-mm格式吗?
if so, you may need to use a custom directive or bind the date field with the date pipe like this: 如果是这样,您可能需要使用自定义指令或将日期字段与日期管道绑定,如下所示:
<input [ngModel]="date | date:'y-MM-dd'" (ngModelChange)="date=$event" type="date" id="datepicker">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.