Angular Directive-My97Date

2015-07-03  本文已影响192人  igordonshaw

directive.js 内容如下

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,用法:
<input ngdatepicker type="text"/>

上一篇下一篇

猜你喜欢

热点阅读