重写 AngularJs DatePicker 弹出窗口以添加新标题

2024-05-05

这个问题说明了一切。

我已经搜寻过高低,但没有找到办法,但是,在我破解模板之前,我想我会在这里问。

只是为了说清楚 - 我希望能够在日期选择器的顶部添加一些文本(这是一个弹出窗口,如果这有什么区别的话),例如“你的生日是什么时候?”。


如果您遵循本主题,有多种方法可以做到这一点:你可以覆盖 AngularUI Bootstrap 中的特定模板吗? https://stackoverflow.com/questions/17660947/can-you-override-specific-templates-in-angularui-bootstrap但我只会限制两种,其中之一是 CSS。

模板覆盖:

笨蛋演示 http://embed.plnkr.co/irYKqYltWopxrPTYm0V1/preview

弹出文件的默认文件是template/datepicker/popup.html,您只需复制文件的内容并向其附加新代码即可。然后新的代码将被包装在里面<script id="template/datepicker/popup.html" type="text/ng-template"> 指示 http://docs.angularjs.org/api/ng.directive%3ascript并放置在<head>

angular.module('ui.bootstrap.demo', ['ngAnimate', 'ui.bootstrap']);
angular.module('ui.bootstrap.demo').controller('DatepickerDemoCtrl', function($scope) {
  $scope.today = function() {
    $scope.dt = new Date();
  };
  $scope.today();

  $scope.clear = function() {
    $scope.dt = null;
  };

  // Disable weekend selection
  $scope.disabled = function(date, mode) {
    return (mode === 'day' && (date.getDay() === 0 || date.getDay() === 6));
  };

  $scope.toggleMin = function() {
    $scope.minDate = $scope.minDate ? null : new Date();
  };
  $scope.toggleMin();
  $scope.maxDate = new Date(2020, 5, 22);

  $scope.open = function($event) {
    $scope.status.opened = true;
  };

  $scope.setDate = function(year, month, day) {
    $scope.dt = new Date(year, month, day);
  };

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

  $scope.formats = ['dd-MMMM-yyyy', 'yyyy/MM/dd', 'dd.MM.yyyy', 'shortDate'];
  $scope.format = $scope.formats[0];

  $scope.status = {
    opened: false
  };

  var tomorrow = new Date();
  tomorrow.setDate(tomorrow.getDate() + 1);
  var afterTomorrow = new Date();
  afterTomorrow.setDate(tomorrow.getDate() + 2);
  $scope.events = [{
    date: tomorrow,
    status: 'full'
  }, {
    date: afterTomorrow,
    status: 'partially'
  }];

  $scope.getDayClass = function(date, mode) {
    if (mode === 'day') {
      var dayToCheck = new Date(date).setHours(0, 0, 0, 0);

      for (var i = 0; i < $scope.events.length; i++) {
        var currentDay = new Date($scope.events[i].date).setHours(0, 0, 0, 0);

        if (dayToCheck === currentDay) {
          return $scope.events[i].status;
        }
      }
    }

    return '';
  };
});

angular.module("template/alert/alert.html", []).run(["$templateCache",
  function($templateCache) {
    $templateCache.put("template/alert/alert.html",
      "      <div class='alert' ng-class='type && \"alert-\" + type'>\n" +
      "          <button ng-show='closeable' type='button' class='close' ng-click='close()'>Close</button>\n" +
      "          <div ng-transclude></div>\n" +
      "      </div>");
  }
]);
.popup-header {
  text-align: center;
  font-weight: bold;
  padding: 10px;
}
<!doctype html>
<html ng-app="ui.bootstrap.demo">

<head>
  <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.js"></script>
  <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular-animate.js"></script>
  <script src="//angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.14.3.js"></script>
  <script src="example.js"></script>
  <link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
  <link href="style.css" rel="stylesheet">

  <!-- Overriding code -->

  <script id="template/datepicker/popup.html" type="text/ng-template">
    <ul class="uib-datepicker-popup dropdown-menu" dropdown-nested ng-if="isOpen" style="display: block" ng-style="{top: position.top+'px', left: position.left+'px'}" ng-keydown="keydown($event)" ng-click="$event.stopPropagation()">
      <!-- Extra code -->

      <div class="popup-header">When is your Birthday?</div>

      <!-- Extra code -->
      <li ng-transclude></li>
      <li ng-if="showButtonBar" style="padding:10px 9px 2px" class="uib-button-bar">
        <span class="btn-group pull-left">
			<button type="button" class="btn btn-sm btn-info uib-datepicker-current" ng-click="select('today')" ng-disabled="isDisabled('today')">{{ getText('current') }}</button>
			<button type="button" class="btn btn-sm btn-danger uib-clear" ng-click="select(null)">{{ getText('clear') }}</button>
		</span>
        <button type="button" class="btn btn-sm btn-success pull-right uib-close" ng-click="close()">{{ getText('close') }}</button>
      </li>
    </ul>
  </script>

  <!-- Overriding code -->
</head>

<body>




  <div ng-controller="DatepickerDemoCtrl">



    <div class="row">
      <div class="col-xs-offset-3 col-xs-6 col-md-3">
        <h4 class="text-center">Date picker Popup</h4>
        <p class="input-group">
          <input type="text" class="form-control date-picker" uib-datepicker-popup="{{format}}" ng-model="dt" is-open="status.opened" min-date="minDate" max-date="maxDate" datepicker-options="dateOptions" date-disabled="disabled(date, mode)" 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>
</body>

</html>

CSS 编辑:

这是一种非标准方式,但无论如何它都不会干扰您的模板结构。

笨蛋演示 http://embed.plnkr.co/FK6p4fuJvFr0rEDpbCEn/preview

:beforeCSS 中的伪元素支持content属性来创建文本。由于您不需要添加除标题文本/标题之外的任何内容,因此这是一个合适的解决方案。检查style.cssPlunkr 中的文件来编辑文本。

angular.module('ui.bootstrap.demo', ['ngAnimate', 'ui.bootstrap']);
angular.module('ui.bootstrap.demo').controller('DatepickerDemoCtrl', function($scope) {
  $scope.today = function() {
    $scope.dt = new Date();
  };
  $scope.today();

  $scope.clear = function() {
    $scope.dt = null;
  };

  // Disable weekend selection
  $scope.disabled = function(date, mode) {
    return (mode === 'day' && (date.getDay() === 0 || date.getDay() === 6));
  };

  $scope.toggleMin = function() {
    $scope.minDate = $scope.minDate ? null : new Date();
  };
  $scope.toggleMin();
  $scope.maxDate = new Date(2020, 5, 22);

  $scope.open = function($event) {
    $scope.status.opened = true;
  };

  $scope.setDate = function(year, month, day) {
    $scope.dt = new Date(year, month, day);
  };

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

  $scope.formats = ['dd-MMMM-yyyy', 'yyyy/MM/dd', 'dd.MM.yyyy', 'shortDate'];
  $scope.format = $scope.formats[0];

  $scope.status = {
    opened: false
  };

  var tomorrow = new Date();
  tomorrow.setDate(tomorrow.getDate() + 1);
  var afterTomorrow = new Date();
  afterTomorrow.setDate(tomorrow.getDate() + 2);
  $scope.events = [{
    date: tomorrow,
    status: 'full'
  }, {
    date: afterTomorrow,
    status: 'partially'
  }];

  $scope.getDayClass = function(date, mode) {
    if (mode === 'day') {
      var dayToCheck = new Date(date).setHours(0, 0, 0, 0);

      for (var i = 0; i < $scope.events.length; i++) {
        var currentDay = new Date($scope.events[i].date).setHours(0, 0, 0, 0);

        if (dayToCheck === currentDay) {
          return $scope.events[i].status;
        }
      }
    }

    return '';
  };
});
.date-picker + .dropdown-menu::before {
  content: "When is your Birthday?";
  font-weight: bold;
  position: relative;
  left: 25%;
}
.date-picker + .dropdown-menu li {
  margin-top: 5px;
}
<!doctype html>
<html ng-app="ui.bootstrap.demo">

<head>
  <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.js"></script>
  <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular-animate.js"></script>
  <script src="//angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.14.3.js"></script>
  <script src="example.js"></script>
  <link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
  <link href="style.css" rel="stylesheet">
</head>

<body>

  <div ng-controller="DatepickerDemoCtrl">



    <div class="row">
      <div class="col-xs-offset-3 col-xs-6 col-sm-offset-4 col-sm-4 col-md-3">
        <h4 class="text-center">Date picker Popup</h4>
        <p class="input-group">
          <input type="text" class="form-control date-picker" uib-datepicker-popup="{{format}}" ng-model="dt" is-open="status.opened" min-date="minDate" max-date="maxDate" datepicker-options="dateOptions" date-disabled="disabled(date, mode)" 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>
</body>

</html>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

重写 AngularJs DatePicker 弹出窗口以添加新标题 的相关文章

随机推荐

  • 从 webdriver 中的文本区域读取文本

    在用 Java 编写 webdriver 测试时 我试图从 textarea 读取文本 由于某种原因 当我使用时我得到了 null getAttribute WebElement text wd findElement By id edit
  • Objective-C 中将 重新定义为另一种符号

    我们有一堂课WayPoint 但在某个时候 我们决定将类重命名为Placemark 然而 我们并不是真的想改变类的名称 因为这会导致现有代码的大量修改 因此 我添加了一行typedef在头文件的底部并开始使用Placemark从那以后 在任
  • 如何在 Scala 中操作 JSON AST

    我正在尝试 json4s 库 基于 lift json 我想做的一件事是将 JSON 字符串解析为 AST 然后对其进行操作 例如 我想更新插入一个字段 如果该字段不存在 则将该字段插入到 AST 中 如果存在 则更新其值 我无法在文档中找
  • 将相机移动到点击的 SCNNode

    我在用着SceneKit and Swift尝试移动相机 使其 聚焦 在所选节点上 我知道我启用了 defaultCameraController 但我试图通过调整相机的位置dolly rotate and translateInCamer
  • 如何选择此“tr”中的下一个“td”? [复制]

    这个问题在这里已经有答案了 我想选择 a 的下一个兄弟姐妹td标签在一个tr元素 The tr元素是这样的 tr td Created On td td 06 28 2018 06 32 td tr 我的 XPATH 代码如下所示 text
  • 使用 Ansible 配置 EC2 实例时遇到问题

    我对如何使用 Ansible 启动 EC2 实例感到非常困惑 我正在尝试使用 ec2 py 库存脚本 我不确定应该使用哪一个 因为 Ansible 安装了三个 ansible lib ansible module utils ec2 py
  • Jquery simplemodal 关闭现有模态并打开一个新模态?

    好的 所以所有模态框的右上角都已经有一个图像来关闭它们 我怎样才能另外制作另一个锚来做同样的事情 我认为我可以使用默认为 simplemodal close 的 closeClass 选项 然后将该类添加到锚点 但它没有达到预期的效果 这是
  • 奇怪的 MSC 8.0 错误:“ESP 的值未在函数调用中正确保存...”

    我们最近尝试将一些 Visual Studio 项目分解为库 并且在测试项目中一切似乎都编译和构建得很好 其中一个库项目作为依赖项 然而 尝试运行该应用程序给我们带来了以下令人讨厌的运行时错误消息 运行时检查失败 0 ESP 的值未在函数调
  • Android TV 嵌入 youtube 1080p

    我想在我的 Android TV 应用程序上显示一些 YouTube 视频 我试图移植一些我已经在手机上运行的东西 但我使用 YouTube Android API 播放器 这似乎不适用于 Android TV 我找到了这个https co
  • Activity 在 Android 上创建两次

    首先 我是 Android 开发新手 所以请耐心等待 我将从用户界面开始 我有一个按钮 一旦您点击它 就会启动一个活动以获取结果 public class GUIActivity extends Activity Override publ
  • 如何检查一个盒子是否适合另一个盒子(允许任何旋转)

    假设我有两个盒子 每个盒子都是一个长方体 http en wikipedia org wiki Rectangular cuboid aka长方体 我需要编写一个函数来决定盒子是否具有尺寸 一 二 三 可以装入具有尺寸的盒子中 甲 乙 丙
  • 错误:将构建上传到 iTunes Connect 时,Swift 支持无效

    我正在提交 TestFlight 发行版的第一个版本 但收到以下错误 位码已关闭 其他答案似乎相当旧 所以我想我会在 2018 年重新询问 无效的 Swift 支持 文件 libswiftDarwin dylib libswiftMetal
  • 扫描图像到可读文本

    我想知道是否有一种方法可以通过编写代码来将带有文本的扫描图像转换为可读文本 那可能吗 OCRTools http www ocrtools com是我用于 net 的 对于Java 我用过Aspire http asprise com pr
  • HIVE 执行错误,从 org.apache.hadoop.hive.ql.exec.DDLTask 返回代码 1

    我在创建配置单元数据库时收到以下错误 FAILED 执行错误 从 org apache hadoop hive ql exec DDLTask 返回代码 1 com facebook fb303 FacebookService Iface
  • 将内部联接和 where 子句添加到 INSERT INTO ON DUPLICATE KEY UPDATE

    我从 INSERT INTO ON DUPLICATE KEY UPDATE MySQL 语句开始 INSERT INTO Table1 field1 field2 VALUES 1 2 ON DUPLICATE KEY UPDATE fi
  • 角度模态弹出窗口中的范围问题

    我的页面上有一个模式弹出窗口 模式弹出窗口使用引导角度库 在模式的主体内部 我有一个带有 ng model 属性的文本框 按下 确定 按钮后 我想使用该文本框值
  • 有没有 C# 到 C 的转换工具? [关闭]

    Closed 此问题正在寻求书籍 工具 软件库等的推荐 不满足堆栈溢出指南 help closed questions 目前不接受答案 我知道 C 与 NET Framework 不同 C 是一种符合 ECMA ECMA 334 和 ISO
  • 如何提取Python代码文件中使用的函数?

    我想创建代码文件中使用的所有函数的列表 例如 如果我们在名为 add random py 的文件中有以下代码 import numpy as np from numpy import linalg def foo print np rand
  • C++ 中的 Ofstream 数组

    我想要在我的项目中使用 41 个输出文件来在其上写入文本 首先创建一个字符串数组list为了命名这些输出文件 然后我尝试定义一个 ofstream 对象数组并使用list命名它们 但我收到此错误 outfile cannot be used
  • 重写 AngularJs DatePicker 弹出窗口以添加新标题

    这个问题说明了一切 我已经搜寻过高低 但没有找到办法 但是 在我破解模板之前 我想我会在这里问 只是为了说清楚 我希望能够在日期选择器的顶部添加一些文本 这是一个弹出窗口 如果这有什么区别的话 例如 你的生日是什么时候 如果您遵循本主题 有