在datepicker angularjs上使用ng-change

yftpprvb  于 2024-01-05  发布在  Angular
关注(0)|答案(2)|浏览(153)

我正在创建一个Web应用程序,其中我想显示在控制台上的ng-change我的datepicker文本框的日期
这是我代码

  1. <div class="form-group">
  2. <h3>Enter Date</h3>
  3. <div id="datepicker" class="input-group date" data-date-format="dd-mm-yyyy">
  4. <span class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></span>
  5. <input class="form-control" ng-model="mddate" ng-blur="chngDate(mddate)" type="text" readonly />
  6. </div>
  7. <style>
  8. label {
  9. margin-left: 20px;
  10. }
  11. #datepicker {
  12. width: 180px;
  13. margin: 0 20px 20px 20px;
  14. }
  15. #datepicker > span:hover {
  16. cursor: pointer;
  17. }
  18. </style>
  19. <script>
  20. $(function () {
  21. $("#datepicker").datepicker({
  22. autoclose: true,
  23. todayHighlight: true
  24. }).datepicker('update', new Date());;
  25. });
  26. </script>
  27. </div>

字符串
但问题是ng-change不适用于bootstrap datepicker,
这是我在控制器中的函数

  1. $scope.chngDate = function (date) {
  2. var dates = new Date();
  3. console.log(dates);
  4. }


我试图在特定的文本框上使用$watch函数,但这也不起作用

  1. $scope.$watch('mddate', function (newValue, oldValue) {
  2. console.log('oldValue=' + oldValue);
  3. console.log('newValue=' + newValue);
  4. //do something
  5. });


这是显示未定义的值在第一,然后该函数不执行
我需要做什么?

8e2ybdfx

8e2ybdfx1#

使用ng-blur代替ng-change,它对我有效

5hcedyr0

5hcedyr02#

试试date-change=“chngDate()”

相关问题