I am building an application with twitter bootstrap,Angular js and Taffy DB.
javascript:
$(function() {
$('#datepicker').datepicker();
});
$scope.submit = function () {
console.log($scope.eventdate);
};
HTML:
<label for="eventdate">Date</label>
<div class="input-append date" id="datepicker" data-date-format="dd-mm-yyyy">
<input class="span2" size="20" type="text" id="eventdate" ng-model="eventdate">
<span class="add-on"><i class="icon-th"></i></span>
</div>
But console.log($scope.eventdate);
is undefined.
Please advice
If you decided to use Angular, put datepicker
into directive:
JS
app.controller('MainCtrl', function($scope) {
$scope.var1 = '12-07-2013';
});
app.directive('datetimez', function() {
return {
restrict: 'A',
require : 'ngModel',
link: function(scope, element, attrs, ngModelCtrl) {
element.datetimepicker({
dateFormat:'dd-MM-yyyy',
language: 'en',
pickTime: false,
startDate: '01-11-2013', // set a minimum date
endDate: '01-11-2030' // set a maximum date
}).on('changeDate', function(e) {
ngModelCtrl.$setViewValue(e.date);
scope.$apply();
});
}
};
});
HTML
<div class="container container-fluid" ng-controller="MainCtrl">
var1={{var1}}
<form class="form-horizontal" novalidate name="form" ng-submit="submit()">
<div class="well">
<div id="date" class="input-append" datetimez ng-model="var1">
<input data-format="MM-dd-yyyy" type="text" id="input1" name="input1"></input>
<span class="add-on">
<i data-time-icon="icon-time" data-date-icon="icon-calendar"></i>
</span>
</div>
</div>
Plunker
Why not use this: http://angular-ui.github.io/bootstrap/ . It has all the bootstrap modules created as Angular directives, thus no need to re-invent the wheel.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With