0
因此,當我點擊md-card上的按鈕選擇日期時,模式會打開。這是它的代碼:在datepicker上設置當前日期AngularJS
<!-- Modal -->
<md-dialog aria-label="Date Picker">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"
aria-hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel">{{modalTitle}}</h4>
</div>
<!-- /.modal-header -->
<div class="modal-body">
<md-input-container flex> <input type="date"
ng-model="startDateL"> </md-input-container>
<md-input-container flex> <label>{{}}</label> <input
type="date" ng-model="endDateL"> </md-input-container>
<!-- /.modal-search-box -->
<md-button ng-click="setDate()" class="md-primary">Update
Date</md-button>
</div>
<!-- /.modal-body -->
</div>
<!-- /.modal-content -->
</div>
<!-- /.modal-dialog -->
</div>
</md-dialog>
<!-- /.modal -->
,這是我的控制器來選擇日期
function datePickerController($scope, $mdDialog, $rootScope, datePickerFactory, $filter){
console.log("suntem in date picker sel");
$scope.startDateL = new Date($rootScope.startDate);
$scope.endDateL = new Date($rootScope.endDate);
$scope.close = function() {
$mdDialog.hide();
console.log("closing");
}
$scope.setDate = function(startDate, endDate) {
$rootScope.startDate = $scope.startDateL;
$rootScope.endDate = $scope.endDateL;
var stDate = $filter('date')($rootScope.startDate,'yyyy-MM-dd');
var enDate = $filter('date')($rootScope.endDate,'yyyy-MM-dd');
console.log(stDate);
console.log(enDate);
datePickerFactory.save({sDate: stDate, eDate: enDate}, function(){
})
localStorage.setItem('chosenStartDate', JSON.stringify($rootScope.startDate));
localStorage.setItem('chosenEndDate', JSON.stringify($rootScope.endDate));
$rootScope.$broadcast("dateWasChosen");
$mdDialog.hide();
}
}
現在的代碼,我想要做的是設置當前日期對我的日期字段在我的模式,以便我有一個默認日期,當我打開我的modal.Is有一個功能,可以設置當前日期?