角度のあるプロジェクトでは、請求書が支払われた日付に関する情報を提供するために使用される bootstrap-ui datepicker があります。
最初に、請求書を作成すると、支払われていないため、null またはそのようなものを示す ng-model 変数が必要です。
$scope.invoice.Payment_Date = null
問題は、datepicker が機能するには有効な日付オブジェクトが必要なようです。このようにすべてを使用する場合、datepicker で日付を選択して請求書が支払われたことを示すと、datepicker は 2016 年 2 月 15 日火曜日のような正しい日付を示しますが、ng-model 変数は null のままです。
変数をそのまま初期化すると:
$scope.invoice.Payment_Date = new Date();
その後、datepicker の日付を変更すると、ng-model が更新されます。
問題は、請求書が支払われたと言わずに請求書を作成/更新する必要がある場合があることです。そうすると、請求書が作成/更新された日付の値を持つ Payment_Date が取得されます。
日付ピッカーをそのままにして、使用時に正しい日付ピッカー値を取得するときに、この変数を null または空に設定したままにする方法はありますか?
誰かが助けてくれることを願っています!
編集:datepickerのHTMLコードは次のとおりです:
<form name="formFacture" novalidate rc-submit="modifierFacture()">
<div class="form-group">
<label>Date de paiement : </label>
<p class="input-group">
<input type="text" class="form-control" uib-datepicker-popup="dd MMMM yyyy" ng-model="facture.Date_Paiement" is-open="popupDatePaiement.opened" datepicker-options="dateOptions" date-disabled="disabled(date, mode)" close-text="Fermer" clear-text="Effacer" current-text="Aujourd'hui" readonly="readonly" ng-click="openDatePaiement()" />
<span class="input-group-btn">
<button type="button" class="btn btn-default" ng-click="openDatePaiement()"><i class="glyphicon glyphicon-calendar"></i></button>
</span>
</p>
</div>
<div class="container text-center">
<button type="submit" class="btn btn-primary">Enregistrer</button>
<div class="btn btn-primary" ng-click="ChangeLocation('prev', '/#factures')">Retour</div>
</div>
</form>
JS コードは次のとおりです。
$scope.facture = {};
$scope.dateOptions = {
startingDay: 1
};
$scope.popupDatePaiement = {
opened: false
};
var openDatePaiement = $scope.openDatePaiement = function() {
$scope.popupDatePaiement.opened = true;
};
$scope.modifierFacture = function(){
console.log($scope.facture);
return
}
コードを確認した後、次のことがわかりました。
- datepicker で有効な日付を取得できます ( ng-model にわずかなエラーがありました) が、日付を 2 回変更すると、facture.Date_Paiement 変数は最初の選択肢のままになり、2 番目の選択肢は転送されません。
- datepicker 内で「クリア」ボタンを使用すると、facture.Date_Paiement 変数が null に戻りません。
私はこの行を追加しようとしました:
$scope.Date_Paiement = null
openDatePaiement 関数内ですが、この場合、facture.Date_Paiement ステータスは常に null になります。