在datepicker angularjs上使用ng-change

yftpprvb  于 6个月前  发布在  Angular
关注(0)|答案(2)|浏览(55)

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

<div class="form-group">
    <h3>Enter Date</h3>
    <div id="datepicker" class="input-group date" data-date-format="dd-mm-yyyy">
        <span class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></span>
        <input class="form-control" ng-model="mddate" ng-blur="chngDate(mddate)" type="text" readonly />
    </div>
    <style>
        label {
            margin-left: 20px;
        }

        #datepicker {
            width: 180px;
            margin: 0 20px 20px 20px;
        }

            #datepicker > span:hover {
                cursor: pointer;
            }
    </style>
    <script>
        $(function () {
            $("#datepicker").datepicker({
                autoclose: true,
                todayHighlight: true
            }).datepicker('update', new Date());;
        });

    </script>
</div>

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

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


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

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


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

8e2ybdfx

8e2ybdfx1#

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

5hcedyr0

5hcedyr02#

试试date-change=“chngDate()”

相关问题