Skip to content
This repository was archived by the owner on Oct 2, 2019. It is now read-only.

Expose $select.search for external / remote filtering. #31

Closed
wants to merge 7 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ angular.module('ui.select', [])
};

ctrl.input = $element.find('input'); // TODO could break if input is at other template

ctrl.refresh = function() {
$timeout(function() {
$scope.$apply($attrs.refresh);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not necessary to $scope.$apply() inside a $timeout()

@tkrotoff or @faxal perhaps you can remove it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ProLoser $attrs.refresh is a string (ex: "refreshAddresses($select.search)") with function refreshAddresses() being declared by the user on the scope (see demo.js#L72).
$scope.$apply() performs an $eval(expr) that's why it works.

$timeout does perform $apply() but without passing any parameter: timeout.js#L52.

$attrs.refresh is like a function pointer as a string. Sounds hackish like this, but it works well.
It is particulary smart, I would not have had the idea myself :)

btw here the current code: select.js#L185.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use $scope.$eval() then.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See a873eb0

});
};
}],

link: function(scope, element, attrs, controllers, transcludeFn) {
Expand Down Expand Up @@ -162,6 +168,7 @@ angular.module('ui.select', [])
}

scope.$watch('$select.search', function() {
$select.refresh();
scope.$select.activeIdx = 0;
ensureHighlightVisible();
});
Expand Down