@@ -147,12 +147,13 @@ import { SelectPopover, SelectPopoverOption } from './select-popover-component';
147
147
providers : [ { provide : NG_VALUE_ACCESSOR , useExisting : Select , multi : true } ] ,
148
148
encapsulation : ViewEncapsulation . None ,
149
149
} )
150
- export class Select extends BaseInput < string [ ] > implements AfterViewInit , OnDestroy {
150
+ export class Select extends BaseInput < string [ ] | string > implements AfterViewInit , OnDestroy {
151
151
152
152
_multi : boolean = false ;
153
153
_options : QueryList < Option > ;
154
154
_texts : string [ ] = [ ] ;
155
155
_text : string = '' ;
156
+ _values : string [ ] = [ ] ;
156
157
157
158
/**
158
159
* @input {string} The text to display on the cancel button. Default: `Cancel`.
@@ -394,7 +395,7 @@ export class Select extends BaseInput<string[]> implements AfterViewInit, OnDest
394
395
set options ( val : QueryList < Option > ) {
395
396
this . _options = val ;
396
397
397
- if ( this . _value . length === 0 ) {
398
+ if ( this . _values . length === 0 ) {
398
399
// there are no values set at this point
399
400
// so check to see who should be selected
400
401
// we use writeValue() because we don't want to update ngModel
@@ -404,14 +405,7 @@ export class Select extends BaseInput<string[]> implements AfterViewInit, OnDest
404
405
}
405
406
}
406
407
407
- _inputNormalize ( val : any ) : string [ ] {
408
- if ( Array . isArray ( val ) ) {
409
- return val ;
410
- }
411
- return [ val + '' ] ;
412
- }
413
-
414
- _inputShouldChange ( val : string [ ] ) : boolean {
408
+ _inputShouldChange ( val : string [ ] | string ) : boolean {
415
409
return ! deepEqual ( this . _value , val ) ;
416
410
}
417
411
@@ -420,11 +414,12 @@ export class Select extends BaseInput<string[]> implements AfterViewInit, OnDest
420
414
*/
421
415
_inputUpdated ( ) {
422
416
this . _texts . length = 0 ;
417
+ this . _values = Array . isArray ( this . _value ) ? this . _value : [ this . _value + '' ] ;
423
418
424
419
if ( this . _options ) {
425
420
this . _options . forEach ( option => {
426
421
// check this option if the option's value is in the values array
427
- option . selected = this . _value . some ( selectValue => {
422
+ option . selected = this . _values . some ( selectValue => {
428
423
return isCheckedProperty ( selectValue , option . value ) ;
429
424
} ) ;
430
425
0 commit comments