1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
angular.module('NG', []).directive('ngdatepicker', function () {
    return {
        restrict: 'A',
        require: '?ngModel',
        link: function ($scope, $element, $attrs, ngModel) {
            $element.on('focus',function(){
                WdatePicker({
                    readOnly: true,
                    onpicked: function(){
                        $scope.$digest();
                    }
                });
            });
            $scope.$watch(function(){
                return $element[0].value
            }, function(newDate){
                eval('$scope.'+$attrs.ngModel+' = newDate;');
            });
        }
    }
});

使用时需依赖jQuery及My97DatePicker,用法:

1
<input ngdatepicker type="text"/>