簡體   English   中英

Angular2 ngModel未定義 <input> 標簽

[英]Angular2 ngModel undefined with <input> tag

我正在使用Angular2和Semantic-UI的分叉版本(包括日歷模塊)。 我正在使用calendardropdown功能:

constructor() {
    setTimeout(() => {
        jQuery('.ui.dropdown').dropdown();
        jQuery('.ui.calendar').calendar({ type: 'date' });
    }, 1000);)
}

這是我的Plunker

如您所見,我無法從日歷選擇中獲得輸入。

我無法理解可能是什么故障。 你能弄明白可能是什么問題嗎?

由於某些未知原因[(ngModel)]沒有得到更新。

但如果它只是獲取日期的問題,你可以使用#templateVariable ,如下所示。

工作演示: https//plnkr.co/edit/X8Gjwzd62DvYN1S8jrFv? p = preview

使用#TemplateVariable

<input #date  type="text" placeholder="Date">

<button (click)="test(date.value)">test</button> 

test(date):void { 
    console.log(date);
    console.log(this.name);
}

使用@ViewChild

@ViewChild('date') date:ElementRef;

 test(date):void { 
       console.log(this.date.nativeElement.value);
        console.log(date);
        console.log(this.name);
 }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM