Skip to content

Commit cfa9400

Browse files
committed
Support strictNullChecks and resetting the control
1 parent 63859cc commit cfa9400

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/demo-app/select/select-demo.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export class SelectDemo {
1616
pokemonDisabled = false;
1717
showSelect = false;
1818
currentDrink: string;
19-
currentDrinkObject: {} = {value: 'tea-5', viewValue: 'Tea'};
19+
currentDrinkObject: {}|undefined = {value: 'tea-5', viewValue: 'Tea'};
2020
currentPokemon: string[];
2121
currentPokemonFromGroup: string;
2222
latestChangeEvent: MdSelectChange;
@@ -106,11 +106,7 @@ export class SelectDemo {
106106
}
107107

108108
setDrinkObjectByCopy(selectedDrink: {}) {
109-
if (selectedDrink) {
110-
this.currentDrinkObject = Object.assign({}, selectedDrink);
111-
} else {
112-
this.currentDrinkObject = undefined;
113-
}
109+
this.currentDrinkObject = selectedDrink ? {...selectedDrink} : undefined;
114110
}
115111

116112
compareDrinkObjectsByValue(d1: {value: string}, d2: {value: string}) {

src/lib/select/select.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,10 @@ export class MdSelect extends _MdSelectMixinBase implements AfterContentInit, On
637637
const optionsArray = this.options.toArray();
638638

639639
const correspondingOption = optionsArray.find((option: MdOption) => {
640+
// Treat null as a special reset value.
641+
if (option.value === null) {
642+
return false;
643+
}
640644
try {
641645
return this._compareWith(option.value, value);
642646
} catch (error) {

0 commit comments

Comments
 (0)