【问题标题】:How to edit datepicker/day.html from uib-datepicker如何从 uib-datepicker 编辑 datepicker/day.html
【发布时间】:2016-02-04 17:22:27
【问题描述】:

uib-datepicker 的文档中有一个名为template-url 的选项

<-- https://angular-ui.github.io/bootstrap/#/datepicker -->

这是内容:

<div ng-switch="datepickerMode" role="application" ng-keydown="keydown($event)">
<uib-daypicker ng-switch-when="day" tabindex="0"></uib-daypicker>
<uib-monthpicker ng-switch-when="month" tabindex="0"></uib-monthpicker>
<uib-yearpicker ng-switch-when="year" tabindex="0"></uib-yearpicker>
</div>

但我需要从“uib-daypicker”修改模板;我尝试从datepicker/day.html 复制模板,但它不起作用,因为它是一个指令......那么,我该怎么办?

【问题讨论】:

    标签: angularjs datepicker angular-ui-bootstrap


    【解决方案1】:

    ----已编辑----

    在库 ui-bootstrap-tpls 中是所有模板:

    • datepicker.html
    • day.html
    • 月.html
    • 年份.html

    datepicker.html:

    <div class="uib-datepicker" ng-switch="datepickerMode" role="application" ng-keydown="keydown($event)">
        <uib-daypicker ng-switch-when="day" tabindex="0"></uib-daypicker>
        <uib-monthpicker ng-switch-when="month" tabindex="0"></uib-monthpicker>
        <uib-yearpicker ng-switch-when="year" tabindex="0"></uib-yearpicker>
    </div>
    

    day.html:

    <table class="uib-daypicker" role="grid" aria-labelledby="{{::uniqueId}}-title" aria-activedescendant="{{activeDateId}}">
      <thead>
        <tr>
              <th><button type="button" class="btn btn-default btn-sm pull-left uib-left" ng-click="move(-1)" tabindex="-1"><i class="glyphicon glyphicon-chevron-left"></i></button></th>
              <th colspan="{{::5 + showWeeks}}"><button id="{{::uniqueId}}-title" role="heading" aria-live="assertive" aria-atomic="true" type="button" class="btn btn-default btn-sm uib-title" ng-click="toggleMode()" ng-disabled="datepickerMode === maxMode" tabindex="-1"><strong>{{title}}</strong></button></th>
              <th><button type="button" class="btn btn-default btn-sm pull-right uib-right" ng-click="move(1)" tabindex="-1"><i class="glyphicon glyphicon-chevron-right"></i></button></th>
            </tr>
        <tr>
              <th ng-if="showWeeks" class="text-center"></th>
              <th ng-repeat="label in ::labels track by $index" class="text-center"><small aria-label="{{::label.full}}">{{::label.abbr}}</small></th>
            </tr>
      </thead>
      <tbody>
        <tr class="uib-weeks" ng-repeat="row in rows track by $index">
          <td ng-if="showWeeks" class="text-center h6"><em>{{ weekNumbers[$index] }}</em></td>
          <td ng-repeat="dt in row" class="uib-day text-center" role="gridcell"
            id="{{::dt.uid}}"
            ng-class="::dt.customClass">
            <button type="button" class="btn btn-default btn-sm"
              uib-is-class="
                'btn-info' for selectedDt,
                'active' for activeDt
                on dt"
              ng-click="select(dt.date)"
              ng-disabled="::dt.disabled"
              tabindex="-1"><span ng-class="::{'text-muted': dt.secondary, 'text-info': dt.current}">{{::dt.label}}</span></button>
          </td>
        </tr>
      </tbody>
    

    moth.html:

    <table class="uib-monthpicker" role="grid" aria-labelledby="{{::uniqueId}}-title" aria-activedescendant="{{activeDateId}}">
      <thead>
        <tr>
              <th><button type="button" class="btn btn-default btn-sm pull-left uib-left" ng-click="move(-1)" tabindex="-1"><i class="glyphicon glyphicon-chevron-left"></i></button></th>
              <th><button id="{{::uniqueId}}-title" role="heading" aria-live="assertive" aria-atomic="true" type="button" class="btn btn-default btn-sm uib-title" ng-click="toggleMode()" ng-disabled="datepickerMode === maxMode" tabindex="-1"><strong>{{title}}</strong></button></th>
              <th><button type="button" class="btn btn-default btn-sm pull-right uib-right" ng-click="move(1)" tabindex="-1"><i class="glyphicon glyphicon-chevron-right"></i></button></th>
            </tr>
      </thead>
      <tbody>
        <tr class="uib-months" ng-repeat="row in rows track by $index">
          <td ng-repeat="dt in row" class="uib-month text-center" role="gridcell"
            id="{{::dt.uid}}"
            ng-class="::dt.customClass">
            <button type="button" class="btn btn-default"
              uib-is-class="
                'btn-info' for selectedDt,
                'active' for ativeDt
                on dt"
              ng-click="select(dt.date)"
              ng-disabled="::dt.disabled"
              tabindex="-1"><span ng-class="::{'text-info': dt.current}">{{::dt.label}}</span></button>
          </td>
        </tr>
      </tbody>
    </table>
    

    年份.html:

    <table class="uib-yearpicker" role="grid" aria-labelledby="{{::uniqueId}}-title" aria-activedescendant="{{activeDateId}}">
      <thead>
        <tr>
              <th><button type="button" class="btn btn-default btn-sm pull-left uib-left" ng-click="move(-1)" tabindex="-1"><i class="glyphicon glyphicon-chevron-left"></i></button></th>
              <th colspan="{{::columns - 2}}"><button id="{{::uniqueId}}-title" role="heading" aria-live="assertive" aria-atomic="true" type="button" class="btn btn-default btn-sm uib-title" ng-click="toggleMode()" ng-disabled="datepickerMode === maxMode" tabindex="-1"><strong>{{title}}</strong></button></th>
              <th><button type="button" class="btn btn-default btn-sm pull-right uib-right" ng-click="move(1)" tabindex="-1"><i class="glyphicon glyphicon-chevron-right"></i></button></th>
            </tr>
      </thead>
      <tbody>
        <tr class="uib-years" ng-repeat="row in rows track by $index">
          <td ng-repeat="dt in row" class="uib-year text-center" role="gridcell"
            id="{{::dt.uid}}"
            ng-class="::dt.customClass">
            <button type="button" class="btn btn-default"
              uib-is-class="
                'btn-info' for selectedDt,
                'active' for activeDt
                on dt"
              ng-click="select(dt.date)"
              ng-disabled="::dt.disabled"
              tabindex="-1"><span ng-class="::{'text-info': dt.current}">{{::dt.label}}</span></button>
          </td>
        </tr>
      </tbody>
    </table>
    

    因此,如果您需要更改其中任何一个模板,您只需使用属性 template-url,例如:

    <div class="uib-datepicker" ng-switch="datepickerMode" role="application" ng-keydown="keydown($event)">
        <uib-daypicker ng-switch-when="day" template-url="template/route/template-day.html" tabindex="0"></uib-daypicker>
        <uib-monthpicker ng-switch-when="month" template-url="template/route/template-moth.html" tabindex="0"></uib-monthpicker>
        <uib-yearpicker ng-switch-when="year" template-url="template/route/template-year.html" tabindex="0"></uib-yearpicker>
    </div>
    

    仅对原始模板进行更改。 Pd:对不起,我的英语不是我的母语。

    【讨论】:

    • 这应该是对您原始帖子的编辑吗?在这里找不到答案,但我找到了一个我会感兴趣的答案,因为我遇到了同样的问题。
    • 我改进了答案,所以我希望这对你有用@jowey
    • 感谢您的回复和努力,但直接更改我的依赖项并不是我的解决方案。我正在寻找使用 dateOptions 的解决方案:datepicker-template-url 和 datepicker-popup-template-url。这对您来说也可能很有趣。
    • 是否可以修改“day.html”以添加年份标题+当前选定日期?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-11
    • 2016-12-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多