@@ -67,11 +67,18 @@ function MdChipsCtrl ($scope, $mdConstant, $log, $element, $timeout) {
6767 this . chipBuffer = '' ;
6868
6969 /**
70- * Whether to use the mdOnAppend expression to transform the chip buffer
70+ * Whether to use the onAppend expression to transform the chip buffer
7171 * before appending it to the list.
7272 * @type {boolean }
7373 */
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 ;
7582}
7683
7784/**
@@ -181,8 +188,8 @@ MdChipsCtrl.prototype.getAdjacentChipIndex = function(index) {
181188 * @param newChip
182189 */
183190MdChipsCtrl . 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 } ) ;
186193 }
187194 if ( this . items . indexOf ( newChip ) + 1 ) return ;
188195 this . items . push ( newChip ) ;
@@ -191,23 +198,34 @@ MdChipsCtrl.prototype.appendChip = function(newChip) {
191198/**
192199 * Sets whether to use the md-on-append expression. This expression is
193200 * 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
195202 * controller cannot know on its own/from the scope whether an expression was
196203 * actually provided.
197204 */
198- MdChipsCtrl . prototype . useMdOnAppendExpression = function ( ) {
199- this . useMdOnAppend = true ;
205+ MdChipsCtrl . prototype . useOnAppendExpression = function ( ) {
206+ this . useOnAppend = true ;
200207} ;
201208
202209/**
203210 * Sets whether to use the md-on-remove expression. This expression is
204211 * 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
206224 * controller cannot know on its own/from the scope whether an expression was
207225 * actually provided.
208226 */
209- MdChipsCtrl . prototype . useMdOnRemoveExpression = function ( ) {
210- this . useMdOnRemove = true ;
227+ MdChipsCtrl . prototype . useOnSelectExpression = function ( ) {
228+ this . useOnSelect = true ;
211229} ;
212230
213231/**
@@ -247,8 +265,8 @@ MdChipsCtrl.prototype.resetChipBuffer = function() {
247265MdChipsCtrl . prototype . removeChip = function ( index ) {
248266 var removed = this . items . splice ( index , 1 ) ;
249267
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 } ) ;
252270 }
253271} ;
254272
@@ -280,6 +298,11 @@ MdChipsCtrl.prototype.selectAndFocusChipSafe = function(index) {
280298MdChipsCtrl . prototype . selectChip = function ( index ) {
281299 if ( index >= - 1 && index <= this . items . length ) {
282300 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+ }
283306 } else {
284307 this . $log . warn ( 'Selected Chip index out of bounds; ignoring.' ) ;
285308 }
0 commit comments