Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

Commit

Permalink
fix(mdContactChips): Compile contact chips against proper scope.
Browse files Browse the repository at this point in the history
After the performance modifications to make autocomplete use the
virtual repeat directive, the contact chips no longer compiled the
contents of the dropdown against the proper scope, so it was loading
a set of blank elements in the autocomplete popup.

This is a hacky way to compile the contents against the proper scope
by creating a new child scope and merging the `item` property onto it
and synching any changes (which is very important since the virtual
repeat re-uses DOM elements).

Fixes #4390.
  • Loading branch information
topherfangio committed Sep 4, 2015
1 parent 218bb93 commit 2b087bb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
27 changes: 27 additions & 0 deletions src/components/chips/js/contactChipsAutocompleteScopeDirective.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
angular
.module('material.components.chips')
.directive('mdContactChipsAutocompleteScope', MdContactChipsAutocompleteScope);

function MdContactChipsAutocompleteScope ($compile, $mdUtil) {
return {
restrict: 'A',
link: postLink,
scope: false
};

function postLink (scope, element, attr) {
// Grab the autocomplete controller's parent scope and create a new one
var newScope = scope.$mdAutocompleteCtrl.parent.$new();

// Watch for changes to our scope's item and copy it to the new scope
scope.$watch('item', function(item) {
$mdUtil.nextTick(function() {
newScope.item = item;
});
});

// TODO: transclude self might make it possible to do this without
// re-compiling, which is slow.
$compile(element.contents())(newScope);
}
}
2 changes: 1 addition & 1 deletion src/components/chips/js/contactChipsDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ var MD_CONTACT_CHIPS_TEMPLATE = '\
md-autoselect\
placeholder="{{$mdContactChipsCtrl.contacts.length == 0 ?\
$mdContactChipsCtrl.placeholder : $mdContactChipsCtrl.secondaryPlaceholder}}">\
<div class="md-contact-suggestion">\
<div class="md-contact-suggestion" md-contact-chips-autocomplete-scope>\
<img \
ng-src="{{item[$mdContactChipsCtrl.contactImage]}}"\
alt="{{item[$mdContactChipsCtrl.contactName]}}" />\
Expand Down

0 comments on commit 2b087bb

Please sign in to comment.