2016-08-01 2 views
0

Date 함수로 모델을 초기화하고 datepicker가있는 입력에 바인딩합니다. 첫 번째 클릭에AngularJS Bootstrap-datepicker 팝업이 처음 클릭 할 때 잘못된 날짜를 표시합니다.

<label>Begin Date</label> 
<div class='input-group date'> 
      <input ng-model="Main.BeginDate" class="form-control" onkeydown="return false" datepicker-popup="MM/dd/yyyy" show-weeks="false" is-open="BeginDate" ng-focus="BeginDate=true" ng-click="BeginDate=true" min-date="Main.MinDate" required/> 
      <span class="input-group-addon"> 
       <span class="glyphicon glyphicon-calendar"></span> 
      </span> 
</div> 

는 날짜 선택기는 실제 날짜가 다른 경우에도 현재 날짜 을 보여줍니다. 그런 다음 다시 입력을 클릭하면 datepicker-popup이 의 올바른 날짜으로 재설정됩니다.

내가 시도 :

은 어떻게받을 수 있나요 min-date 속성 모델에 바인딩 날짜를 표시하는 팝업을 제거 $filter

  • 사용자 정의 new Date() 기능
  • 를 사용

    • 서식 날짜를?

      내가 사용하고 있습니다 :

      • AngularJS와의 v1.5.0
      • 부트 스트랩 v3.3.6
      • 각도-UI-부트 스트랩 버전 : 0.13.4

      먼저 클릭 ---- - >>>>> enter image description here

      두 번째 클릭 ----- >>>>enter image description here

  • 답변

    1

    나는 상황을 점검하고 사용중인 버전이 어떻게 든 상충되는 것처럼 보입니다. 각도 1.4.9 이하를 사용하고 코드를 모두 사용해도 제대로 작동하는 것 같습니다. 여기에 plunker이 있습니다. 그러나 각도 1.5.0 이상을 사용하자마자 나는 당신과 같은 문제에 직면하게됩니다. 각도 1.4.9 및 각도 Ui 부트 스트랩 0.13.4를 사용하거나 각도 Ui 부트 스트랩 버전을 업그레이드 할 수 있습니다.

    index.html을

    <!doctype html> 
    <html ng-app="app"> 
        <head> 
        <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.js"></script> 
        <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular-animate.js"></script> 
        <script src="//angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.13.4.js"></script> 
        <script src="example.js"></script> 
        <link href="//netdna.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"> 
        </head> 
        <body> 
    
    <div ng-controller="DateCtrl" style="padding:40px"> 
        <label>Begin Date</label> 
    <div class='input-group date'> 
          <input ng-model="dt" class="form-control" onkeydown="return false" datepicker-popup="MM/dd/yyyy" show-weeks="false" is-open="BeginDateOpen" ng-focus="BeginDateOpen=true" ng-click="BeginDateOpen=true" min-date="Main.MinDate" required/> 
          <span class="input-group-addon"> 
           <span class="glyphicon glyphicon-calendar"></span> 
          </span> 
    </div> 
    
    </div> 
        </body> 
    </html> 
    

    example.js @Amit에서 언급 한 바와 같이

    angular.module('app', ['ui.bootstrap']); 
    angular.module('app').controller('DateCtrl', function ($scope) { 
    
    $scope.today = function(){ 
        $scope.dt = new Date(1998,1,5) 
    } 
    $scope.today(); 
    }); 
    
    +0

    감사합니다. 다른 라이브러리가 해당 버전에 종속되어 있으므로 Angular를 1.5 이하로 변경할 수 없습니다. UI 부트 스트랩을 0.13.4에서 1.0.0 또는 2.0.1로 변경하려고했습니다. 그러나 팝업은 절대로 나타나지 않았습니다. https://plnkr.co/edit/15euZAV2vERLC6KS6Hgf. 그러나 그것을 고칠 수있는 또 다른 방법을 찾았습니다. 나는 답을 추가했다. 감사. – Mahesh

    1

    는 문제는 라이브러리의 버전과의 호환성이 될 것으로 보인다.

    here으로 표시된 버그를 기반으로 atttribute init-date를 추가하는 솔루션이 효과가있었습니다. 여기

    <input ng-model="dt" class="form-control" 
         onkeydown="return false" datepicker-popup="MM/dd/yyyy" show-weeks="false" 
         is-open="BeginDateOpen" ng-focus="BeginDateOpen=true" ng-click="BeginDateOpen=true" 
         min-date="Main.MinDate" required 
         init-date="dt"/> 
    

    은에 대한 plunker

    관련 문제