angular - Angular 4+ - 如何从输入日期选择器中获取日期
问题描述
我是角度的新手。
我有一个输入日期选择器。我想获取/获取在日期选择器中选择的日期。
代码:HTML文件:
<input class="form-control m-input " id="m_datepicker_2_validate" placeholder="Select Date" readonly="" type="text">
我正在尝试 console.log 选定的日期。
在 component.ts 文件中,我添加了一个变量staff_date_booking : Date;
并创建了一个函数
bookStaffEmployeeDate(){
console.log("This is the DATE:", this.staff_book_date);
}
在我添加的 html 中
<input [ngModel]="staff_book_date | date:'yyyy-MM-dd'" class="form-control m-input " id="m_datepicker_2_validate" placeholder="Select Date" readonly="" type="text">
选择日期后,我将在(单击)上调用此函数,但 this.staff_book_date 未定义。
如何将选定的日期存储在像 staff_book_date 这样的变量中
解决方案
不要在里面使用管道ngModel
。此外,使用中的双向绑定ngModel
<input [(ngModel)]="staff_book_date"
推荐阅读
- elasticsearch - ElasticSearch异常检测:启用model_plot_config时不处理最后一个bucket
- java - 在 GPU 服务器上提交作业后 Spark 挂起:INFO TaskSchedulerImpl:添加任务集 0.0 和 4 个任务资源配置文件 0
- android - 在 Android Studio 中的 ViewModel 的情况下,添加的依赖项仍显示预期的类或接口
- reactjs - 如何制作一个接受嵌套 RadioButton 组件的可重用 RadioGroup 组件
- c++ - VS Code 未在终端中显示输出
- mysql - SQL 查询获取最新的非空值,CURDATE()+2 不再工作
- python - 如何从python中的matplotlib轴标签(从合并列表生成)中删除引号?
- java - 使用 Java EE 自定义 JRE(雅加达)
- reactjs - 如何在功能组件中使用 ReactTransitionGroup 回调
- asp.net - 无法获取在 vb.net 的网络表单中单击了哪个动态添加的按钮