繁体   English   中英

AngularJS UI Bootstrap DatePicker无法正常运行

[英]AngularJS UI Bootstrap DatePicker Not Functioning Correctly

我有一个定义如下的指令:

模板

<div class="date-picker">
    <div class="row">
        <div class="col-md-6">
            <label for="{{datePickerId}}">{{labelText}}</label>
            <p class="input-group">
                <input type="text"
                       id="{{datePickerId}}"
                       class="form-control"
                       datepicker-popup="{{format}}"
                       ng-model="dt"
                       is-open="opened"
                       datepicker-options="dateOptions"
                       disabled="disabled"
                       ng-required="true"
                       close-text="Close" />
                <span class="input-group-btn">
                    <button type="button" class="btn btn-default" ng-click="open($event)"><i class="glyphicon glyphicon-calendar"></i></button>
                </span>
            </p>
        </div>
    </div>
</div>

指示

//TypeScript

module MyApp.Directives {
    /** Scope for Messaging directive. */
    export interface IMaDatePickerScope extends ng.IScope {
        dt: Date;
        today(): void;
        clear(): void;
        disabled(date, mode): boolean;
        open($event): void;
        opened: boolean;
        dateOptions;
        formats: string[];
        format: string;
    }


    export class MaDatePicker implements ng.IDirective {
        restrict = "E";
        templateUrl = TEMPLATES + 'ma-date-picker.html';
        replace = true;
        transclude = true;
        scope = {
            labelText: '@',
            datePickerId: '='
        }
        link = (scope: IMaDatePickerScope) => {
            scope.today = () => {
                scope.dt = new Date();
            }
            scope.today();

            scope.clear = () => {
                scope.dt = null;
            }
            scope.disabled = (date: Date, mode) => {
                return (mode == 'day' && (date.getDay() === 0 || date.getDay() === 6)); //disable Saturday and Sunday
            }
            scope.open = ($event) => {
                $event.preventDefault();
                $event.stopPropagation();
                scope.opened = true;
            }

            scope.dateOptions = {
                formatYear: 'yy',
                startingDay: 1
            }

            scope.formats = ['yyyy-MM-dd', 'dd-MMMM-yy', 'yyyy/MM/dd', 'dd.MM.yyyy', 'shortDate'];
            scope.format = scope.formats[0];            
        }
        controller = ($scope: IMaDatePickerScope) => {

        }
    }
}

它取自此处的DatePicker部分 ,其功能应类似于该页面上显示的弹出版本。 每当我单击日历按钮启动指令时,日历就会以损坏的方式显示。 此外,当我单击弹出式日历中的“下个月”箭头时,日历会继续向左扩展。 我的代码有问题吗? 我没有为此添加任何样式,因为根据站点似乎没有任何样式,但是我想在拆解现有样式之前检查代码中是否有明显错误的地方。

没有看到您可能包含的CSS文件,我无法确切说明罪魁祸首,尽管如果您将Twitter Bootstrap与除Angular UI Bootstrap之外的其他CSS库一起使用,则您很可能会遇到一个或多个样式冲突。这些其他CSS文件更多。 我发现隔离这些问题的最简单方法是使用Chrome浏览器开发人员工具检查CSS覆盖及其来源,并准确查看冲突的位置,然后更新我的自定义CSS来解决这些问题。 我不建议修改Twitter Bootstrap之类的OTB CSS库以实现可维护性。 始终使用自己的自定义CSS文件。 我在日期选择器上确实遇到了类似的问题,花了一些时间才找出它们在哪里。 如果确实是您的情况,那么使用多个CSS库是有危险的。 狩猎愉快!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM