My create event page initializes my date picker to current date. That works fine. But when I want to edit the event on my edit page, i'm not sure how to set the date picker value to the event I have in my php variable.
Do I need a different angular module for that?
Any help would be greatly appreciated
HTML
<div ng-app="ui.bootstrap.demo">
<div ng-controller="DatepickerDemoCtrl">
<?php
// How to set date picker to value of $event->event_start
// $event->event_start
?>
<p class="input-group">
<input type="text" id="dt_start" class="form-control" readonly datepicker-popup="@{{format}}" ng-model="dt1" is-open="opened1" max-date="'2020-06-22'" datepicker-options="dateOptions" date-disabled="disabled(date, mode)" ng-required="true" close-text="Close" />
<span class="input-group-btn">
<button type="button" class="btn btn-default" ng-click="open($event,'opened1')"><i class="glyphicon glyphicon-calendar"></i></button>
</span>
</p>
<timepicker
ng-model="dt1"
hour-step="1"
minute-step="15"
show-meridian="true">
</timepicker>
JS
angular
.module('ui.bootstrap.demo', ['ngAnimate', 'ui.bootstrap'])
.controller('DatepickerDemoCtrl', function ($scope) {
$scope.today = function() {
var dt1 = new Date();
dt1.setHours( dt1.getHours() + 1 );
dt1.setMinutes( 0 );
$scope.dt1 = dt1;
};
$scope.today();
$scope.clear = function () {
$scope.dt1 = null;
};
Updated HTML and JS with Alan Tsai's suggestion - still not working as expected - datepicker working, but timepicker still empty
HTML
<?php
$dateeventstart = new DateTime($event->event_start);
?>
<div ng-app="ui.bootstrap.demo">
<div ng-controller="DatepickerDemoCtrl" ng-init="initModel('<?php echo $dateeventstart->format("Y-m-d H:i") ?>', '<?php echo $dateeventstart->format("Y-m-d H:i") ?>'">)
<?php
// How to set date picker to value of $event->event_start
// $event->event_start
?>
<p class="input-group">
<input type="text" id="dt_start" class="form-control" readonly datepicker-popup="@{{format}}" ng-model="dt1" is-open="opened1" max-date="'2020-06-22'" datepicker-options="dateOptions" date-disabled="disabled(date, mode)" ng-required="true" close-text="Close" />
<span class="input-group-btn">
<button type="button" class="btn btn-default" ng-click="open($event,'opened1')"><i class="glyphicon glyphicon-calendar"></i></button>
</span>
</p>
<timepicker
ng-model="tm1"
hour-step="1"
minute-step="15"
show-meridian="true">
</timepicker>
HTML source (controller)
<div ng-controller="DatepickerDemoCtrl" ng-init="initModel('2015-09-02 12:15', '2015-09-02 12:15')">
JS
angular
.module('ui.bootstrap.demo', ['ngAnimate', 'ui.bootstrap'])
.controller('DatepickerDemoCtrl', function ($scope) {
$scope.today = function() {
var dt1 = new Date();
dt1.setHours( dt1.getHours() + 1 );
dt1.setMinutes( 0 );
$scope.dt1 = dt1;
};
$scope.today();
$scope.clear = function () {
$scope.dt1 = null;
};
$scope.initModel = function(datePickerValue, timePickerValue){
$scope.dt1 = datePickerValue;
$scope.tm1 = timePickerValue;
}