2017-09-13 105 views
0

我正在使用datetimepicker(取自https://eonasdan.github.io/bootstrap-datetimepicker/)並希望將日期的值存儲在ng-model中。但是,即使我們進行了通常的數據綁定,日期也不存儲。datetimepicker bootstrap數據綁定不起作用

HTML

<div class="form-group col-xs-3 col-sm-3 col-md-3 col-lg-3 input-group date" id="equipList"> 
     <label for="date">Selection of Year</label> 
     <input type="text" id="datetimepicker11" class="form-control" placeholder="Year" data-ng-model="yearFilter"/> 
     </div> 

     {{yearFilter}} 

JS

$(document).ready(function() { 

     $('#datetimepicker11').datetimepicker({ 
       viewMode: 'years', 
       format: 'YYYY' 
      }); 
}); 

回答

0

我用這個來解決這個問題:

$(document).ready(function() { 

     $('#datetimepicker11').datetimepicker({ 
       viewMode: 'years', 
       format: 'YYYY' 
      }); 

     $("#datetimepicker11").on("dp.change", function() { 

     $scope.yearFilter = $("#datetimepicker11").val(); 

    }); 
});