AngularJSでKendoを使用しているDatePickerコントロールの日付が表示されない場合があります
1690 ワード
AngularJSでKendoのDatePickerコントロールを使用する場合、k-ng-modelで日付オブジェクトがバインドされていますが、ページが表示されている場合、コントロールが空白になっている場合もありますが、正常でランダムな場合もあります.stackoverflowでも同様の状況や解決策は見つかりません.分析追跡後、問題がDatePickerコントロールの問題であることを確認します.コントロールの説明ドキュメントのng-modelとk-ng-modelには違いがあります. The first is to demonstrate the difference between
ng-modelバインドはstringタイプの変数であり、k-ng-modelはオブジェクト変数をバインドし、両者がバインドされている場合、コントロールはng-modelバインドの変数を表示するので、コントロールのng-modelとk-ng-modelを値付けすることができ、値が正常で正しく表示されることを保証します.
HTMLコード:
JavaScriptコード:
js日付オブジェクトのgetMonthが返す月は0から11なので、上のコードには1が追加されています.
ng-model="dateString"
and k-ng-model="dateObject"
. dateString
is bound to the input field's contents as a string — so it gets the formatted string date, while dateObject
is bound to the widget's value()
which in the case of DatePicker
returns a JS Date
object. As you can see, we can apply the Angular date
filter on it. ng-modelバインドはstringタイプの変数であり、k-ng-modelはオブジェクト変数をバインドし、両者がバインドされている場合、コントロールはng-modelバインドの変数を表示するので、コントロールのng-modelとk-ng-modelを値付けすることができ、値が正常で正しく表示されることを保証します.
HTMLコード:
<input kendo-date-picker k-ng-model="datestart" ng-model="datestartString" />
JavaScriptコード:
$scope.datestart = new Date();
$scope.datestartString = $scope.datestart.getFullYear() + '-' + ($scope.datestart.getMonth() + 1) + '-' + $scope.datestart.getDate();
js日付オブジェクトのgetMonthが返す月は0から11なので、上のコードには1が追加されています.