ngDialog中的UI Bootstrap datepicker没有

时间:2015-11-09 15:41:51

标签: javascript angularjs twitter-bootstrap datepicker

我正在尝试在ngDialog中使用ui-bootstrap日期选择器,但我只能打开一次。当我选择日期时,选择器已关闭,我无法再打开它。 请参阅plunker:http://plnkr.co/edit/obmNAWXAnCtNqa2YmioF

的index.html:

<!DOCTYPE html>
<html ng-app="plunker">

<head>
  <meta charset="utf-8" />
  <title>AngularJS Plunker</title>
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/ng-dialog/0.4.0/js/ngDialog.min.js"></script>
  <script src="ui-bootstrap-tpls-0.14.3.min.js" type="text/javascript"></script>
  <script src="app.js"></script>

  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/ng-dialog/0.4.0/css/ngDialog.min.css" />
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/ng-dialog/0.4.0/css/ngDialog-theme-default.min.css" />
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" />
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css" />
</head>

<body ng-controller="MainCtrl">
  <button ng-click="showCreateOrderPopup()">Create order</button>
</body>

</html>

app.js:

var app = angular.module('plunker', ["ngDialog", "ui.bootstrap"]);

app.controller('MainCtrl', ['$scope', 'ngDialog', function($scope, ngDialog) {
  $scope.dateOptions = {
    formatYear: "yy",
    startingDay: 1,
    format: "shortDate"
  }

  $scope.createOrder = "";    
  $scope.showCreateOrderPopup = function() {
    ngDialog.openConfirm({
      template: "createOrderPopup.html",
      showClose: true,
      scope: $scope
    });
  }

  $scope.openedCreate = false;
  $scope.openDatePickerCreate = function($event) {
    $event.preventDefault();
    $event.stopPropagation();

    $scope.openedCreate = true;
  };
}]);

弹出:

<form name="createOrderForm">
  <div class="row">
    <div class="form-group">
      <label for="createOrderStart">Start Time</label>
      <div>
        <div ng-class="{'has-error' : createOrderForm.createOrderStart.$error.required}">
          <div class="input-group">
            <input ng-model="createOrder.startTime" type="text" class="form-control" id="createOrderStart" name="createOrderStart" uib-datepicker-popup="shortDate" is-open="openedCreate" datepicker-options="dateOptions" current-text="Today" required clear-text="Clear"
            close-text="Close" ng-readonly="false" />
            <span class="input-group-btn">
            <button type="button" class="btn btn-primary" ng-click="openDatePickerCreate($event)">Cal</button>
            </span>
          </div>
        </div>
      </div>
    </div>
  </div>
</form>

奇怪的是,当我动态添加datepicker(使用ngRepeat)时,一切正常。

任何想法如何使这项工作? 提前谢谢。

1 个答案:

答案 0 :(得分:2)

对不起,我刚刚意识到你在说什么。

将您的代码更改为以下内容:

$scope.status= {opened: false}
$scope.openDatePickerCreate = function ($event) {
    $scope.status.opened = true;
};

另外,将您的html更改为以下内容:

is-open="status.opened"

所有这些都是因为原型继承而发生的。你可能想研究一下。