I am using Angular ui-select to create a "search-and-select component". When the user types into the search field, it immediately filters a list of items as a free-text filter. Additionally, the user can select options from the dropdown, which are used as exact search terms in the filter (e.g. filter by a category).
I have created an additional directive that extends <ui-select>
in order to access the $select.search
value from that scope. This variable contains the free-text typed by the user. My question is how can I pass this to the parent controller?
Ideally, I'd like something like the following:
<ui-select
my-ui-select
on-search-changed="searchChanged(newValue, oldValue)"
multiple
ng-model="ctrl.myModel">
<!-- ... -->
</ui-select>
My custom directive would call the on-search-changed
callback with the free text values. The problem is that I cannot define a scope for my-ui-select
directive because it would conflict with the ui-select
scope.
How can I pass a callback method to my custom directive, while still being able to access the ui-select
scope? Or is there a better way to achieve what I'm after?
I created a Plunker based on the ui-select examples. I have defined the myUiSelect
directive which uses console.log
to output the search terms. What I want is to call the DemoCtrl.searchChanged
method from there.