2

I'm trying to get the date from a bootstrap datetimepicker but when I put a ng-model on the input field it's not working?

html

<!-- EndDate -->
<div class="form-group">
    <label for="dtp_enddate">Eind datum:</label>
    <div class="input-group date" id="dtp_endDate">
        <input type="text" class="form-control" name="EndDate" ng-model="employeeCtrl.employee.EndDate" required="required" />
            <span class="input-group-addon">
                <span class="glyphicon glyphicon-calendar"></span>
            </span>
    </div>
</div>

jquery

   $(function() {
        $('#dtp_endDate').datetimepicker({
            useCurrent: true,
            collapse: true,
            format: 'YYYY-MM-D',
            locale: 'nl',
            allowInputToggle: true
        });
    });

How could I accomplish that?

2
  • could you create a plnkr plnkr.co or or codepen codepen.io Commented Apr 11, 2016 at 12:52
  • also try avoiding usage of any 3rd party libraries along with angularjs, like in your case usage of jquery. Whatever you can do with Jquery is possible with angularjs as well. more info for your reference :stackoverflow.com/questions/14994391/… Commented Apr 11, 2016 at 12:57

4 Answers 4

2

It is not the best practice to combine angularJS with jQuery plugins. There is a plenty of plugins converted to angularJS directives, which you could try to use. E.g. https://github.com/dalelotts/angular-bootstrap-datetimepicker

Sign up to request clarification or add additional context in comments.

Comments

1

If you need date-time-picker in a single component you can use http://dalelotts.github.io/angular-bootstrap-datetimepicker/ or you can use 2 components (datepicker and timepicker) from Angular Bootstrap

Comments

1

for example

<input type="text" datepicker-popup="dd-MMMM-yyyy" ng-model="dt" />
in this example date is binding to dt (ng-model="dt")

you can get data by $scope.dt if you want to watch the date change you can do

$scope.$watch('dt',function(val){
   //to do       
   console.log(val)
})

Comments

0

Include id ="dtp_endDate" inside input tag

<input type="text" id="dtp_endDate" class="form-control" name="EndDate" ng-model="employeeCtrl.employee.EndDate" required="required" />

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.