From daf680f0bc3a6e6460e5ae6894893970e684c3dc Mon Sep 17 00:00:00 2001 From: Thomas Burleson Date: Mon, 27 Apr 2015 20:06:55 -0500 Subject: [PATCH] fix(chips): fix $apply already in progress Fixes #2458. Fixes #2544. Closes #2591. --- src/components/chips/js/chipDirective.js | 7 ++++--- src/components/chips/js/chipsController.js | 10 ++++++---- 2 files changed, 10 insertions(+), 7 deletions(-) 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 () {