This repository was archived by the owner on Sep 5, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +28
-2
lines changed
src/components/datepicker Expand file tree Collapse file tree 2 files changed +28
-2
lines changed Original file line number Diff line number Diff line change 251
251
252
252
var self = this ;
253
253
ngModelCtrl . $render = function ( ) {
254
- self . date = self . ngModelCtrl . $viewValue ;
255
- self . inputElement . value = self . dateLocale . formatDate ( self . date ) ;
254
+ var value = self . ngModelCtrl . $viewValue ;
255
+
256
+ if ( value && ! ( value instanceof Date ) ) {
257
+ throw Error ( 'The ng-model for md-datepicker must be a Date instance. ' +
258
+ 'Currently the model is a: ' + ( typeof value ) ) ;
259
+ }
260
+
261
+ self . date = value ;
262
+ self . inputElement . value = self . dateLocale . formatDate ( value ) ;
256
263
self . resizeInputElement ( ) ;
257
264
self . setErrorFlags ( ) ;
258
265
} ;
Original file line number Diff line number Diff line change @@ -99,6 +99,25 @@ describe('md-date-picker', function() {
99
99
expect ( controller . inputElement . placeholder ) . toBe ( 'Fancy new placeholder' ) ;
100
100
} ) ;
101
101
102
+ it ( 'should throw an error when the model is not a date' , function ( ) {
103
+ expect ( function ( ) {
104
+ pageScope . myDate = '2015-01-01' ;
105
+ pageScope . $apply ( ) ;
106
+ } ) . toThrowError ( 'The ng-model for md-datepicker must be a Date instance. ' +
107
+ 'Currently the model is a: string' ) ;
108
+ } ) ;
109
+
110
+ it ( 'should support null and undefined values' , function ( ) {
111
+ expect ( function ( ) {
112
+ pageScope . myDate = null ;
113
+ pageScope . $apply ( ) ;
114
+
115
+ pageScope . myDate = undefined ;
116
+ pageScope . $apply ( ) ;
117
+
118
+ } ) . not . toThrow ( ) ;
119
+ } ) ;
120
+
102
121
it ( 'should throw an error when inside of md-input-container' , function ( ) {
103
122
var template =
104
123
'<md-input-container>' +
You can’t perform that action at this time.
0 commit comments