1

我一直在尝试在我的一个应用程序中使用 angular-daterangepicker。我正在关注这个链接:

https://github.com/fragaria/angular-daterangepicker

  1. 安装了模块。
  2. 在控制器中写入依赖项。
  3. 使用脚本标签在 .html/.ejs 文件中添加依赖项。
<script src="jquery/dist/jquery.min.js"></script>
<script src="jquery-ui/jquery-ui.js"></script>
<script src="angular/angular.min.js"></script> 
<script src="moment/moment.js"></script>
<script src="angular-daterangepicker/bootstrap-   daterangepicker/daterangepicker.js"></script>
<script src="angular-daterangepicker/js/angular-daterangepicker.js"></script>
<link rel="stylesheet" href="angular-daterangepicker/bootstrap-dist/css/bootstrap.css"/>
<link rel="stylesheet" href="angular-daterangepicker/bootstrap-daterangepicker/daterangepicker.css"/>

$scope.datePicker.date = {startDate: null, endDate: null}; //in controller if i use this i get error (2)
<input date-range-picker class="form-control date-picker" type="text" ng-model="datePicker.date" />

错误 :

1) TypeError: el.daterangepicker 不是函数

2)TypeError:无法设置未定义的属性“日期”

如何摆脱这个错误?

4

1 回答 1

0

这是一个工作示例 - 你需要从https://github.com/fragaria/angular-daterangepicker下载并包含“angular-daterangepicker.min.js”这个文件

<head>
    <meta charset="utf-8">
    <title>Daterange picker example</title>

    <!-- bower:css -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" />
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-daterangepicker/2.1.13/daterangepicker.min.css" />
    <!-- endbower -->

</head>

<body>
    <!-- bower:js -->
    <script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.20/angular.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.20/angular-messages.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.6/moment.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-daterangepicker/2.1.13/daterangepicker.min.js"></script>
    <!-- endbower -->

    <script src="angular-daterangepicker-master/js/angular-daterangepicker.min.js"></script>

<div class="container">
    <h1>Daterange picker example</h1>

    <div class="row">
        <div class="col-md-6" ng-controller="TestCtrl">
            <form name="dateForm" class="form-horizontal">
                <div class="form-group">
                    <label for="daterange1" class="control-label">Simple picker</label>
                    <input date-range-picker id="daterange1" name="daterange1" class="form-control date-picker" type="text"
                           ng-model="date" required/>
                </div>
      </form>

            <div class="row">
                <h4>Model:</h4>
                <div class="col-md-12 well">
                    <label>Date range:</label><br>
                    {{date | json}}<br>
                    <label>Single date:</label><br>
                    {{singleDate | json}}<br>
                </div>
            </div>
        </div>
    </div>
</div>
</body>


<script>
exampleApp = angular.module('example', ['ngMessages', 'daterangepicker']);
exampleApp.controller('TestCtrl', function($scope) {
    $scope.date = {
        startDate: null,
        endDate: null
    };


});

angular.bootstrap(document, ['example']);</script>

</html>
于 2017-01-23T08:48:22.797 回答