我的Ionic应用程序需要一个日期选择器。我试图使用这个,因为它似乎很受欢迎:
我尝试按照教程操作,但效果很好,但日期按钮不会根据日期选择进行更新。我该如何更新?
我的代码如下。
这是我的控制者:
app.controller('EnterDatapointCtrl', function($scope, $state) {
$scope.datepickerObject = {
titleLabel: 'Title', //Optional
inputDate: new Date(), //Optional
callback: function (val) { //Mandatory
datePickerCallback(val);
}
};
var datePickerCallback = function (val) {
if (typeof(val) === 'undefined') {
console.log('No date selected');
} else {
console.log('Selected date is : ', val)
}
};
});
这是我的模板:
<ion-view view-title="New Sales">
<ion-content class="padding">
<ionic-datepicker input-obj="datepickerObject">
<button class="button button-block button-positive"> {{datepickerObject.inputDate | date:'dd - MMMM - yyyy'}}</button>
</ionic-datepicker>
<div class="list list-inset">
<label class="item item-input">
<input type="text" placeholder="Amount" ng-model="data.amount">
</label>
</div>
<button class="button button-block button-stable" ng-click="save()">Save</button>
</ion-content>
</ion-view>
答案 0 :(得分:1)
我在回调中添加了一行。我不明白我应该修改回调函数。
$scope.datepickerObject.inputDate = val;
app.controller('EnterDatapointCtrl', function($scope, $state) {
$scope.datepickerObject = {
titleLabel: 'Title', //Optional
inputDate: new Date(), //Optional
callback: function (val) { //Mandatory
datePickerCallback(val);
}
};
var datePickerCallback = function (val) {
if (typeof(val) === 'undefined') {
console.log('No date selected');
} else {
console.log('Selected date is : ', val)
$scope.datepickerObject.inputDate = val;
}
};
$scope.save = function() {
$state.go('confirm-datapoint');
};
});