From 9a2759702dc401c59bd8e7ca99723383f22b79e4 Mon Sep 17 00:00:00 2001 From: Topher Fangio Date: Fri, 18 Sep 2015 12:29:52 -0500 Subject: [PATCH] fix(mdAutocomplete): Fix scope watch bug. Commit 8849213ce42fa98169b6fbbb0805feb95a6ba678 introduced a scope watching bug cauinsg the autocomplete to no longer update it's list of items as you scrolled (since it re-uses DOM elements). Fix by swapping nextTick to be inside the watch statement. Fixes #4713. Closes #4715. --- .../js/autocompleteParentScopeDirective.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/components/autocomplete/js/autocompleteParentScopeDirective.js b/src/components/autocomplete/js/autocompleteParentScopeDirective.js index a712632b677..c348e59cbc6 100644 --- a/src/components/autocomplete/js/autocompleteParentScopeDirective.js +++ b/src/components/autocomplete/js/autocompleteParentScopeDirective.js @@ -10,7 +10,7 @@ function MdAutocompleteItemScopeDirective($compile, $mdUtil) { }; function postLink(scope, element, attr) { - var ctrl = scope.$mdAutocompleteCtrl; + var ctrl = scope.$mdAutocompleteCtrl; var newScope = ctrl.parent.$new(); var itemName = ctrl.itemName; @@ -32,10 +32,13 @@ function MdAutocompleteItemScopeDirective($compile, $mdUtil) { * @param variable * @param alias */ - function watchVariable (variable, alias) { - $mdUtil.nextTick(function () { - newScope[alias] = scope[variable]; - scope.$watch(variable, function (value) { newScope[alias] = value; }); + function watchVariable(variable, alias) { + newScope[alias] = scope[variable]; + + scope.$watch(variable, function(value) { + $mdUtil.nextTick(function() { + newScope[alias] = value; + }); }); } }