我正在使用 Angular2 和 Semantic-UI 的 fork 版本(包括日历模块)。我正在使用 calendar
和 dropdown
功能:
constructor() {
setTimeout(() => {
jQuery('.ui.dropdown').dropdown();
jQuery('.ui.calendar').calendar({ type: 'date' });
}, 1000);)
}
这里是 my 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);
}
关于select - Angular2 ngModel undefined with <input> 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39875660/