@@ -115,6 +115,10 @@ export class Dropdown implements OnInit, AfterContentInit, OnDestroy {
115115 * @memberof Dropdown
116116 */
117117 @Input ( ) scrollableContainer : string ;
118+ /**
119+ * Specifies the property to be used as the return value to `ngModel`
120+ */
121+ @Input ( ) value : string ;
118122 /**
119123 * Accessible label for the button that opens the dropdown list.
120124 * Defaults to the `DROPDOWN.OPEN` value from the i18n service.
@@ -221,15 +225,17 @@ export class Dropdown implements OnInit, AfterContentInit, OnDestroy {
221225 this . view . size = this . size ;
222226 this . elementRef . nativeElement . classList . add ( this . buildClass ( ) ) ;
223227 this . view . select . subscribe ( event => {
224- if ( this . type === "single" ) {
225- this . closeMenu ( ) ;
226- this . dropdownButton . nativeElement . focus ( ) ;
227- }
228228 if ( this . type === "multi" ) {
229229 this . propagateChange ( this . view . getSelected ( ) ) ;
230230 } else {
231- if ( event . item . selected ) {
232- this . propagateChange ( event . item ) ;
231+ this . closeMenu ( ) ;
232+ this . dropdownButton . nativeElement . focus ( ) ;
233+ if ( event . item && event . item . selected ) {
234+ if ( this . value ) {
235+ this . propagateChange ( event . item [ this . value ] ) ;
236+ } else {
237+ this . propagateChange ( event . item ) ;
238+ }
233239 } else {
234240 this . propagateChange ( null ) ;
235241 }
@@ -266,12 +272,16 @@ export class Dropdown implements OnInit, AfterContentInit, OnDestroy {
266272 * @memberof Dropdown
267273 */
268274 writeValue ( value : any ) {
269- if ( value ) {
270- if ( this . type === "single" ) {
271- this . view . propagateSelected ( [ value ] ) ;
275+ if ( this . type === "single" ) {
276+ if ( this . value ) {
277+ const newValue = Object . assign ( { } , this . view . items . find ( item => item [ this . value ] === value ) ) ;
278+ newValue . selected = true ;
279+ this . view . propagateSelected ( [ newValue ] ) ;
272280 } else {
273- this . view . propagateSelected ( value ) ;
281+ this . view . propagateSelected ( [ value ] ) ;
274282 }
283+ } else {
284+ this . view . propagateSelected ( value ) ;
275285 }
276286 }
277287
0 commit comments