@@ -67,11 +67,18 @@ function MdChipsCtrl ($scope, $mdConstant, $log, $element, $timeout) {
67
67
this . chipBuffer = '' ;
68
68
69
69
/**
70
- * Whether to use the mdOnAppend expression to transform the chip buffer
70
+ * Whether to use the onAppend expression to transform the chip buffer
71
71
* before appending it to the list.
72
72
* @type {boolean }
73
73
*/
74
- this . useMdOnAppend = false ;
74
+ this . useOnAppend = false ;
75
+
76
+ /**
77
+ * Whether to use the onSelect expression to notify the component's user
78
+ * after selecting a chip from the list.
79
+ * @type {boolean }
80
+ */
81
+ this . useOnSelect = false ;
75
82
}
76
83
77
84
/**
@@ -181,8 +188,8 @@ MdChipsCtrl.prototype.getAdjacentChipIndex = function(index) {
181
188
* @param newChip
182
189
*/
183
190
MdChipsCtrl . prototype . appendChip = function ( newChip ) {
184
- if ( this . useMdOnAppend && this . mdOnAppend ) {
185
- newChip = this . mdOnAppend ( { '$chip' : newChip } ) ;
191
+ if ( this . useOnAppend && this . onAppend ) {
192
+ newChip = this . onAppend ( { '$chip' : newChip } ) ;
186
193
}
187
194
if ( this . items . indexOf ( newChip ) + 1 ) return ;
188
195
this . items . push ( newChip ) ;
@@ -191,23 +198,34 @@ MdChipsCtrl.prototype.appendChip = function(newChip) {
191
198
/**
192
199
* Sets whether to use the md-on-append expression. This expression is
193
200
* bound to scope and controller in {@code MdChipsDirective} as
194
- * {@code mdOnAppend }. Due to the nature of directive scope bindings, the
201
+ * {@code onAppend }. Due to the nature of directive scope bindings, the
195
202
* controller cannot know on its own/from the scope whether an expression was
196
203
* actually provided.
197
204
*/
198
- MdChipsCtrl . prototype . useMdOnAppendExpression = function ( ) {
199
- this . useMdOnAppend = true ;
205
+ MdChipsCtrl . prototype . useOnAppendExpression = function ( ) {
206
+ this . useOnAppend = true ;
200
207
} ;
201
208
202
209
/**
203
210
* Sets whether to use the md-on-remove expression. This expression is
204
211
* bound to scope and controller in {@code MdChipsDirective} as
205
- * {@code mdOnRemove}. Due to the nature of directive scope bindings, the
212
+ * {@code onRemove}. Due to the nature of directive scope bindings, the
213
+ * controller cannot know on its own/from the scope whether an expression was
214
+ * actually provided.
215
+ */
216
+ MdChipsCtrl . prototype . useOnRemoveExpression = function ( ) {
217
+ this . useOnRemove = true ;
218
+ } ;
219
+
220
+ /*
221
+ * Sets whether to use the md-on-select expression. This expression is
222
+ * bound to scope and controller in {@code MdChipsDirective} as
223
+ * {@code onSelect}. Due to the nature of directive scope bindings, the
206
224
* controller cannot know on its own/from the scope whether an expression was
207
225
* actually provided.
208
226
*/
209
- MdChipsCtrl . prototype . useMdOnRemoveExpression = function ( ) {
210
- this . useMdOnRemove = true ;
227
+ MdChipsCtrl . prototype . useOnSelectExpression = function ( ) {
228
+ this . useOnSelect = true ;
211
229
} ;
212
230
213
231
/**
@@ -247,8 +265,8 @@ MdChipsCtrl.prototype.resetChipBuffer = function() {
247
265
MdChipsCtrl . prototype . removeChip = function ( index ) {
248
266
var removed = this . items . splice ( index , 1 ) ;
249
267
250
- if ( removed && removed . length && this . useMdOnRemove && this . mdOnRemove ) {
251
- this . mdOnRemove ( { '$chip' : removed [ 0 ] , '$index' : index } ) ;
268
+ if ( removed && removed . length && this . useOnRemove && this . onRemove ) {
269
+ this . onRemove ( { '$chip' : removed [ 0 ] , '$index' : index } ) ;
252
270
}
253
271
} ;
254
272
@@ -280,6 +298,11 @@ MdChipsCtrl.prototype.selectAndFocusChipSafe = function(index) {
280
298
MdChipsCtrl . prototype . selectChip = function ( index ) {
281
299
if ( index >= - 1 && index <= this . items . length ) {
282
300
this . selectedChip = index ;
301
+
302
+ // Fire the onSelect if provided
303
+ if ( this . useOnSelect && this . onSelect ) {
304
+ this . onSelect ( { '$chip' : this . items [ this . selectedChip ] } ) ;
305
+ }
283
306
} else {
284
307
this . $log . warn ( 'Selected Chip index out of bounds; ignoring.' ) ;
285
308
}
0 commit comments