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

Commit

Permalink
update(autocomplete): re-adds support for user-defined item value i…
Browse files Browse the repository at this point in the history
…n `md-selected-item-change`

Related to #3637
  • Loading branch information
Robert Messerle committed Jul 13, 2015
1 parent 2b42358 commit c5b3131
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
35 changes: 34 additions & 1 deletion src/components/autocomplete/autocomplete.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,39 @@ describe('<md-autocomplete>', function() {
expect(scope.itemChanged.calls.mostRecent().args[0]).toBeNull();
expect(scope.selectedItem).toBeNull();
}));
});
it('should pass value to item watcher', inject(function($timeout, $mdConstant) {
var scope = createScope();
var itemValue = null;
var template = '\
<md-autocomplete\
md-selected-item="selectedItem"\
md-search-text="searchText"\
md-items="item in match(searchText)"\
md-selected-item-change="itemChanged(item)"\
md-item-text="item.display"\
placeholder="placeholder">\
<span md-highlight-text="searchText">{{item.display}}</span>\
</md-autocomplete>';
scope.itemChanged = function(item) {
itemValue = item;
};
var element = compile(template, scope);
var ctrl = element.controller('mdAutocomplete');

element.scope().searchText = 'fo';
ctrl.keydown({});
element.scope().$apply();
$timeout.flush();

ctrl.select(0);
element.scope().$apply();
$timeout.flush();

expect(itemValue).not.toBeNull();
expect(itemValue.display).toBe('foo');

ctrl.clear();
element.scope().$apply();
}));
});
});
2 changes: 1 addition & 1 deletion src/components/autocomplete/js/autocompleteController.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ function MdAutocompleteCtrl ($scope, $element, $mdUtil, $mdConstant, $timeout, $
* Use the user-defined expression to announce changes each time a new item is selected
*/
function announceItemChange() {
angular.isFunction($scope.itemChange) && $scope.itemChange();
angular.isFunction($scope.itemChange) && $scope.itemChange(getItemAsNameVal($scope.selectedItem));
}

function announceTextChange() {
Expand Down

0 comments on commit c5b3131

Please sign in to comment.