how to bind Bootstrap-datepicker element with angularjs ng-model?

后端 未结 11 749
囚心锁ツ
囚心锁ツ 2020-11-30 04:44

Here is the html for the date field :

11条回答
  •  Happy的楠姐
    2020-11-30 05:31

    Using this datepicker I had the same problem. I solved it using a little trick.

    In the inputs tag I added a new attribute (dp-model):

    
    
    ...
    

    And then in the js file I forced the binding in this way:

    $scope.formData.dp = []; // arrays of yours datepicker models
    $('.dp').datepicker().on('changeDate', function(ev){
        $scope.formData.dp[$(ev.target).attr('dp-model')] = $(ev.target).val();
    });
    

提交回复
热议问题