0
如何獲取輸入的選定日期並將標記<p>
。Angular2 - 日期選擇器的綁定
我正在使用jqueryUI datepicker,我試圖做綁定嘗試捕獲與更改並單擊事件,但沒有奏效。
任何人都可以幫助我嗎?
<input [(ngModel)]="date" type="date" id="datepicker">
該編譯器告訴你,格式必須是YYYY-MM-DD格式:
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;
}
}
你可能想看看ngModel https://angular.io/ docs/ts/latest/api/forms/index/NgModel-directive.html –
它只在輸入時寫入綁定。 ''但是當我使用日曆不會做綁定 – rafaelcb21
注入'ChangeDetectorRef'https://angular.io/ docs/ts/latest/api/core/index/ChangeDetectorRef-class.html,並調用'markForCheck'或'detectChanges'來觸發更新。還可以查看'DoCheck'生命週期鉤子https://angular.io/docs/ts/latest/guide/lifecycle-hooks.html#!#docheck,這是您在'ChangeDetectorRef'上進行調用的位置 –