【发布时间】:2016-04-19 03:21:24
【问题描述】:
这是日期字段的 html:
<div class='form-group'>
<label>Check out</label>
<input type='text' ng-model='checkOut' class='form-control' data-date-format="yyyy-mm-dd" placeholder="Check out" required id="check-out">
</div>
<script>
$('#check-out').datepicker();
</script>
日期选择器显示在输入字段中。但是,如果我在我的控制器中这样做:
console.log($scope.checkOut);
我收到undefined in the javascript console。
如何解决这个问题?
有没有更好的方法来使用bootstrap-datepicker 和angularjs ?
我不想使用 angular-ui/angular-strap,因为我的项目充满了 javascript 库。
【问题讨论】:
-
试试
ng-model="$parent.checkOut" -
您不能在
$digest循环之外绑定到datepicker()。 -
尝试将 Angular-UI-Bootstrap 的 datepicker 指令与 Bootstrap 一起使用,我已经将它与 Bootstrap 2 和 3 一起使用并且效果很好 - angular-ui.github.io/bootstrap/#/datepicker(我应该注意你可以只包含指令脚本如果你担心库膨胀,Angular-UI-Bootstrap 日期选择器)
-
您可以在此处仅使用日期选择器创建自定义 Angular-UI-Bootstrap 缩小库:angular-ui.github.io/bootstrap/#/getting_started
-
我想指出,如果您使用的是 AngularJS 1.3+,则 angular-ui 引导程序目前不是一个可行的选择这是一个已知问题:github.com/angular-ui/bootstrap/issues/2830
标签: javascript jquery twitter-bootstrap angularjs datepicker