datepicker - 角度 Material md-datepicker 无法在 ionic 模式下工作

标签 datepicker ionic-framework modal-dialog angular-material

我正在尝试在 ionic 模态中使用角度 Material md-datepicker,并且在使用日期选择器并且更改日期时没有触发 ng-change 事件,日期选择器本身不会滚动,并且不会'看起来不可点击。当我尝试在模式之外使用日期选择器时,一切正常。这是怎么回事?

<script id="add-location-modal.html" type="text/ng-template">
  <ion-modal-view>
<ion-content>
  <md-content layout-padding>
    <form name="myForm" style="">
        <md-datepicker ng-model="date" ng-change="updateDate(date)" md-placeholder="Date"></md-datepicker>
    </form>
  </md-content>
</ion-content>

这是 Controller :

angular.module('myModule')
   .controller('TripDetailsCtrl'['$scope','$rootScope','$stateParams','tripServices','tripLocationServices','$ionicModal',
   function($scope,$rootScope,$stateParams,tripServices,tripLocationServices,$ionicModal){

$scope.trip = [],$scope.tripData = {}, $scope.addLocationModal, $scope.locationData = {},$scope.date;

$scope.showAddLocationModal = function(){
  $scope.addLocationModal.show();
};

$scope.closeAddLocationModal = function(){
  $scope.addLocationModal.hide();
};

var initModal = function(){
  if(!$scope.addLocationModal){
    $ionicModal.fromTemplateUrl('add-location-modal.html', {
      scope: $scope,
      animation: 'slide-in-up'
    }).then(function(modal) {
      $scope.addLocationModal = modal;
    });
  }
};


  initModal();

最佳答案

这是因为角度 Material 会将日历面板附加到文档正文而不是 ionic 模态。当您处于 ionic 模式并且日历位于模式之外时,您看不到它。解决方案是破解 angular-material.js。

首先在你的 ionic 模式中创建一个div,例如:

    <ion-modal-view class="datepickerModal">
      <ion-header-bar>
        <h1 class="title">Select a date to view history</h1>
        <div class="buttons">
          <button class="button button-calm" ng-click="closeDatepickerModal()">Close</button>
        </div>
      </ion-header-bar>
      <ion-content>
         <md-content>
           <h4>Date-picker with min date and max date</h4>
           <md-datepicker ng-model="myDate" md-placeholder="Enter date" md-min-date="minDate" md-max-date="maxDate"></md-datepicker>

           <!-- give the div an ID-->
           <div id="ionicCalendar"></div>
           <!--End -->

         </md-content>
      </ion-content>
    </ion-modal-view>

然后你需要转到 angular-material.js (不是分钟)。搜索:

 document.body.appendChild(calendarPane);

并将其替换为您自己的区域,例如:

document.getElementById('ionicCalendar').appendChild(calendarPane);

您将在模式中看到您的日历。它仍然会有点奇怪,但它正在起作用。你需要与 ionic css 进行斗争,让它看起来像样。还要确保您的 js 和 css 版本匹配

CSS 类似:

.datepickerModal md-content{
    height:100%;
}
.datepickerModal .bar{
    background-color:#11c1f3;
}
.datepickerModal .bar h1.title{
    font-size:14px !important;
}

enter image description here

关于datepicker - 角度 Material md-datepicker 无法在 ionic 模式下工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36534630/

相关文章:

javascript - 根据日期选择器选择日期和月份更改两个下拉菜单选择选项

node.js - 安装cordova和ionic,错误: ECONNRESET,没有解决方案

objective-c - iOS 8 表单模式对话框显示后调整大小

jquery - 如何克隆已被 jQuery UI Widget 绑定(bind)的元素?

java - Appium Android中如何处理datepicker

javascript - 避免在选择日期后重新打开日期选择器

angularjs - 如何让 Controller 在 Angularjs 中刷新?

mysql - 如何将ibeacon信息发布到服务器

swift - 将 View 作为参数传递给按钮,将其触发为模态

jquery - twitter bootstrap 模态,内部有弹出窗口