Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 通过jquery日期选择器生成指令_Angularjs_Jquery Ui_Angularjs Directive - Fatal编程技术网

Angularjs 通过jquery日期选择器生成指令

Angularjs 通过jquery日期选择器生成指令,angularjs,jquery-ui,angularjs-directive,Angularjs,Jquery Ui,Angularjs Directive,我使用jQueryUIDatePicker发出了一个指令,代码如下 app.directive('jqdatepicker', ['$parse', '$filter', function ($parse, $filter) { return { restrict: 'A', require: 'ngModel', link: function (scope, element, attrs, ngModelCtrl) {

我使用jQueryUIDatePicker发出了一个指令,代码如下

app.directive('jqdatepicker', ['$parse', '$filter', function ($parse, $filter) {
    return {
        restrict: 'A',
        require: 'ngModel',
        link: function (scope, element, attrs, ngModelCtrl) {

            //Used to parse date format
            function formatter(value) {
                if (value) {
                    return jQuery.datepicker.formatDate(options.dateFormat, value);
                }
                return null;
            }

            //Used to parse date format
            function parseDate(value) {
                if (angular.isString(value)) {
                    return jQuery.datepicker.parseDate(options.dateFormat, value);
                }
                return null;
            }

            //select date
            var updateModel = function (dateText) {
                scope.$apply(function () {
                    ngModelCtrl.$setViewValue(dateText);
                });
            };

            //date picker options
            var options = {
                dateFormat: "dd/mm/yy",
                onSelect: function (dateText) {
                    updateModel(dateText);
                }
            };

            //parsing
            ngModelCtrl.$formatters.push(formatter);
            ngModelCtrl.$parsers.unshift(parseDate);

            // If we don't destroy the old one it doesn't update properly when the config changes
            element.datepicker('destroy');
            //bind datepicker
            element.datepicker(options);
            // Force a render to override whatever is in the input text box
            //ngModelCtrl.$render();
        }
    };
}]);
指令的使用

<input ng-if="VM_Volunteer.isEdit" type="text" jqdatepicker class="form-control" ng-model="VM_Volunteer.dateOfBirth">

当我选择日期时,日期设置为我的文本框,这没有问题,但在将此日期保存到我的数据库后,我获取此日期并希望显示在此文本框中,但日期不显示。当我得到这个日期时,它是格式化日期。我的问题是什么。

simple scope.$watchattrs.ngModel,jquery datepicker*/}中的函数{/*set value应该可以工作。或者使用ngModelCtrl$viewChangeListeners@PetrAveryanov,谢谢你的回复。我已经使用过这个函数,但是如果我像element.datepickersetDate一样使用它,则为value;日期不对。它正在从实际日期更改。