1

最初,当我加载它时它工作正常,但是当我更改模板 URl 中用于 ng-model scope.value 的值时,我的链接中未定义。我正在为 datepicker bootstrap angularjs 制定指令。

dateTime .directive("DatePicker", function(){
            
             return {
                        restrict: "E",
                        transclude: true,
                        require: "ngModel",
                        scope:{
                            ngModel: "=",
                            dateOptions: "=",
                            opened: "="
                        },
            
                        link: function($scope, element, attrs, datepickerModel) {
            
                            $scope.open = function(event){
                                event.preventDefault();
                                event.stopPropagation();
                                $scope.opened = true;
                            };
            
                            $scope.myModel = new Date();
                            datepickerModel.$setViewValue($scope.myModel);
            
                            $scope.$watch('myModel',function(){
                                console.log("value changed"+$scope.myModel);
                                datepickerModel.$setViewValue($scope.myModel);
                                console.log($scope.myModel);
                            })
            
                        template: ' <input type="date" class="form-control" datepicker-popup="{{format}}" ng-model="myModel" is-open="opened" min-date="minDate" max-date="'2015-06-22'" datepicker-options="dateOptions" date-disabled="disabled(date, mode)" ng-required="true" close-text="Close" />'
                    }
                })
4

0 回答 0