diff --git a/src/components/chips/js/chipDirective.js b/src/components/chips/js/chipDirective.js index 40a69fd80c5..4f28244f28f 100644 --- a/src/components/chips/js/chipDirective.js +++ b/src/components/chips/js/chipDirective.js @@ -43,12 +43,13 @@ function MdChip($mdTheming) { function compile(element, attr) { element.append(DELETE_HINT_TEMPLATE); return function postLink(scope, element, attr, ctrl) { + element.addClass('md-chip'); + $mdTheming(element); + if (ctrl) angular.element(element[0].querySelector('.md-chip-content')) .on('blur', function () { - ctrl.$scope.$apply(function () { ctrl.selectedChip = -1; }); + ctrl.selectedChip = -1; }); - element.addClass('md-chip'); - $mdTheming(element); }; } } diff --git a/src/components/chips/js/chipsController.js b/src/components/chips/js/chipsController.js index f2f3a823eb1..a43bab57885 100644 --- a/src/components/chips/js/chipsController.js +++ b/src/components/chips/js/chipsController.js @@ -336,20 +336,22 @@ MdChipsCtrl.prototype.configureUserInput = function(inputElement) { inputElement .attr({ tabindex: 0 }) .on('keydown', function(event) { scope.$apply(function() { ctrl.inputKeydown(event); }); }) - .on('focus', function () { this.$scope.$apply(this.onInputFocus.bind(this)); }.bind(this)) - .on('blur', function () { this.$scope.$apply(this.onInputBlur.bind(this)); }.bind(this)); + .on('focus', ctrl.onInputFocus.bind(ctrl) ) + .on('blur', ctrl.onInputBlur.bind(ctrl) ); }; MdChipsCtrl.prototype.configureAutocomplete = function(ctrl) { + ctrl.registerSelectedItemWatcher(function (item) { if (item) { this.appendChip(item); this.resetChipBuffer(); } }.bind(this)); + this.$element.find('input') - .on('focus', function () { this.$scope.$apply(this.onInputFocus.bind(this)); }.bind(this)) - .on('blur', function () { this.$scope.$apply(this.onInputBlur.bind(this)); }.bind(this)); + .on('focus',this.onInputFocus.bind(this) ) + .on('blur', this.onInputBlur.bind(this) ); }; MdChipsCtrl.prototype.hasFocus = function () {