0

I have a directive defined as follows:

Template

<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>

Directive

//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) => {

        }
    }
}

It is taken from the DatePicker section here and is supposed to function like the popup version shown on that page. Whenever I click the calendar button to initiate the directive, however, the calendar appears in a broken way. Additionally, the calendar keeps expanding to the left when I click on the "next month" arrow in the popup calendar. Is there something wrong in my code? I didn't add any styling with this, as there doesn't seem to be any according to the site, but I wanted to check if there was anything obviously wrong with the code before taking apart my existing styling.

4

1 回答 1

0

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

于 2014-11-04T17:15:54.273 回答