Angular2 ngModel未定义<input />标记

时间:2016-10-05 13:43:17

标签: select angular calendar semantic-ui angular2-ngmodel

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

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

这是my Plunker

如您所见,我无法从日历选择中获得输入。

我无法理解可能是什么故障。你能弄明白可能是什么问题吗?

1 个答案:

答案 0 :(得分:3)

由于某些未知原因 [(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);
 }
相关问题