引导-日期选择器不能与angularjs NG-模型绑定 [英] Bootstrap-datepicker not binding with angularjs ng-model
问题描述
下面是HTML的日期字段:
Here is the html for the date field :
<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>
在日期选择器在输入字段中显示出来。但是,如果我这样做在我的控制器:
The datepicker shows up in the input field. However if I do this in my controller :
console.log($scope.checkOut);
我得到未定义的JavaScript控制台
。
如何解决此问题?结果
有没有办法使用更好的方法引导,日期选择器
与 angularjs
?
我不希望使用角UI /角带
,因为我的项目是臃肿的JavaScript库。
I don't want to use angular-ui/angular-strap
since my project is bloated with javascript libraries.
推荐答案
由于@lort建议,您无法访问您的控制器中的日期选择器模式,因为该日期选择器拥有自己的私人范围。
As @lort suggests, you cannot access the datepicker model from your controller because the datepicker has its own private scope.
如果你设置: NG-模式=parent.checkOut
和定义控制器: $ scope.parent = {结帐:''};
您可以通过访问日期选择器: $ scope.parent.checkOut
you can access the datepicker using: $scope.parent.checkOut
这篇关于引导-日期选择器不能与angularjs NG-模型绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!