如何将datepicker绑定到ngmodel



在我的表单中设置日期选择器:https://bootstrap-datepicker.readthedocs.io/en/latest/

<div class="input-group date" data-provide="datepicker" >
<input type="text" class="form-control">
<div class="input-group-addon"  >
<span class="glyphicon glyphicon-th"></span>
</div>
</div>

如何将此添加到ngModel中?

将它与其他输入(如文本)绑定的方式相同,radio完全不起作用。

<input type="text" class="form-control" name="mytext" ngModel> <-- works
<div class="input-group date" data-provide="datepicker" >
<input type="text" class="form-control"  name="mydate" ngModel> <-- doesnt work
<div class="input-group-addon"  >
<span class="glyphicon glyphicon-th"></span>
</div>
</div>

正如您所看到的,我希望以与其他输入完全相同的方式绑定它。
component.ts知道mydate的新字段,但它仍然是空的。

您需要为日期选择器逻辑实现ControlValueAccessor接口。

这将花费相当多的时间,在一天结束时,你有一个很好的机会做一个克隆的ng-bootstrap或ngx-bootstrap。你可以考虑马上使用其中一个。这两个已经被社区完善了。

最新更新