@@ -15,6 +15,8 @@ import {
15
15
ViewEncapsulation ,
16
16
Inject ,
17
17
Optional ,
18
+ ChangeDetectionStrategy ,
19
+ ChangeDetectorRef ,
18
20
} from '@angular/core' ;
19
21
import { ENTER , SPACE } from '../keyboard/keycodes' ;
20
22
import { coerceBooleanProperty } from '@angular/cdk' ;
@@ -54,19 +56,27 @@ export class MdOptionSelectionChange {
54
56
'class' : 'mat-option' ,
55
57
} ,
56
58
templateUrl : 'option.html' ,
57
- encapsulation : ViewEncapsulation . None
59
+ encapsulation : ViewEncapsulation . None ,
60
+ changeDetection : ChangeDetectionStrategy . OnPush ,
58
61
} )
59
62
export class MdOption {
60
63
private _selected : boolean = false ;
61
64
private _active : boolean = false ;
65
+ private _multiple : boolean = false ;
62
66
63
67
/** Whether the option is disabled. */
64
68
private _disabled : boolean = false ;
65
69
66
70
private _id : string = `md-option-${ _uniqueIdCounter ++ } ` ;
67
71
68
72
/** Whether the wrapping component is in multiple selection mode. */
69
- multiple : boolean = false ;
73
+ get multiple ( ) { return this . _multiple ; }
74
+ set multiple ( value : boolean ) {
75
+ if ( value !== this . _multiple ) {
76
+ this . _multiple = value ;
77
+ this . _changeDetectorRef . markForCheck ( ) ;
78
+ }
79
+ }
70
80
71
81
/** The unique ID of the option. */
72
82
get id ( ) { return this . _id ; }
@@ -87,6 +97,7 @@ export class MdOption {
87
97
88
98
constructor (
89
99
private _element : ElementRef ,
100
+ private _changeDetectorRef : ChangeDetectorRef ,
90
101
@Optional ( ) public readonly group : MdOptgroup ,
91
102
@Optional ( ) @Inject ( MATERIAL_COMPATIBILITY_MODE ) public _isCompatibilityMode : boolean ) { }
92
103
@@ -112,12 +123,14 @@ export class MdOption {
112
123
/** Selects the option. */
113
124
select ( ) : void {
114
125
this . _selected = true ;
126
+ this . _changeDetectorRef . markForCheck ( ) ;
115
127
this . _emitSelectionChangeEvent ( ) ;
116
128
}
117
129
118
130
/** Deselects the option. */
119
131
deselect ( ) : void {
120
132
this . _selected = false ;
133
+ this . _changeDetectorRef . markForCheck ( ) ;
121
134
this . _emitSelectionChangeEvent ( ) ;
122
135
}
123
136
@@ -132,7 +145,10 @@ export class MdOption {
132
145
* events will display the proper options as active on arrow key events.
133
146
*/
134
147
setActiveStyles ( ) : void {
135
- this . _active = true ;
148
+ if ( ! this . _active ) {
149
+ this . _active = true ;
150
+ this . _changeDetectorRef . markForCheck ( ) ;
151
+ }
136
152
}
137
153
138
154
/**
@@ -141,7 +157,10 @@ export class MdOption {
141
157
* events will display the proper options as active on arrow key events.
142
158
*/
143
159
setInactiveStyles ( ) : void {
144
- this . _active = false ;
160
+ if ( this . _active ) {
161
+ this . _active = false ;
162
+ this . _changeDetectorRef . markForCheck ( ) ;
163
+ }
145
164
}
146
165
147
166
/** Ensures the option is selected when activated from the keyboard. */
@@ -161,6 +180,7 @@ export class MdOption {
161
180
_selectViaInteraction ( ) : void {
162
181
if ( ! this . disabled ) {
163
182
this . _selected = this . multiple ? ! this . _selected : true ;
183
+ this . _changeDetectorRef . markForCheck ( ) ;
164
184
this . _emitSelectionChangeEvent ( true ) ;
165
185
}
166
186
}
0 commit comments