Angularjs 如何查看Angular ui的新ui select(以前的ui-select2)搜索字符串更改?
我注意到Angular UI已经停止了他们的UI-Select2指令,转而使用具有多个主题的新UI-Select-Select2、bootstrap、selectize 看起来是这样的:Angularjs 如何查看Angular ui的新ui select(以前的ui-select2)搜索字符串更改?,angularjs,angularjs-directive,angularjs-scope,angular-ui,ui-select2,Angularjs,Angularjs Directive,Angularjs Scope,Angular Ui,Ui Select2,我注意到Angular UI已经停止了他们的UI-Select2指令,转而使用具有多个主题的新UI-Select-Select2、bootstrap、selectize 看起来是这样的: <ui-select multiple ng-model="multipleDemo.colors" theme="select2" ng-disabled="disabled" style="width: 300px;"> <ui-select-match placeholder="
<ui-select multiple ng-model="multipleDemo.colors" theme="select2" ng-disabled="disabled" style="width: 300px;">
<ui-select-match placeholder="Select colors...">{{$item}}</ui-select-match>
<ui-select-choices repeat="color in availableColors | filter:$select.search">
{{color}}
</ui-select-choices>
</ui-select>
<p>Selected: {{multipleDemo.colors}}</p>
不起作用
编辑:
有关任何人的参考,请参阅以下简短讨论:
编辑2:
我通过在指令中使用$emit解决了这个问题,因此该值现在在我的控制器中可用。但现在我想知道如何覆盖指令的这一部分,使指令本身保持不变,以便在将来的更新中不会中断?我通过在指令的正确位置创建一个事件,然后$emitting它来解决它-最终我能够在控制器中侦听事件并使用该值 这样做的缺点是,我已将其直接放在第三方指令中,因此无法安全更新。我需要找到一种方法来推翻这个指令。如果您有任何想法,请告诉我。似乎有一个on select属性,请参阅: 使用元素上的“刷新”属性以$select.search作为参数调用作用域上的函数:
<ui-select-choices repeat="color in multipleDemo.availableColors | filter:$select.search"
refresh="refreshColors($select.search)"
refresh-delay="0">
{{color}}
</ui-select-choices>
然后使用此代码段中的函数refreshColor相应地更新multipleDemo.availableColors
您还可以使用refresh delay属性指定函数去抖动的毫秒数,以避免快速连续调用太多次
我也在multipleDemo上添加了可用的颜色,就像您在multipleDemo.colors上所做的一样
参考:在“示例:异步”部分下。使用ngInit获取值
<div ui-select ng-init="mySelect = $select"></div>
<button ng-click="search(mySelect.search)">Search</button>
请容忍我,这是我的第一个答案 因此,目前的首要答案对我来说并不适用。只是想提供另一种选择。ui select choices上的refresh属性不会触发my scope中的命名函数 我按照信息访问UI select for custom features。创建一个自定义指令,在其中监视$select.search like 指令'myUiSelect',函数{ 返回{ 要求:'uiSelect', 链接:functionscope、元素、属性、$select{ 范围.$watch'$select.search',函数搜索{ 如果搜索{ ... } }; } };
};我相信这是在选择一个选项后执行的。我需要的是在输入字符或其阈值时触发一个操作。下次运行bower update ui时,请选择此处并取消将其标记为答案。顺便说一句,你查过克里斯·邦德的答案了吗?只要你不需要在ng-repeat里面就可以了。你在重复这个答案吗?在这种情况下,您可以将第二个参数传递给refresh函数以标识实例。mmmm是的……但是感觉还好吗?看,我想你有点像。。。。。。要使refresh函数知道上下文,请像refresh=refreshColorsitem$select.search这样传入它。然后,您可以访问每个项的所有有用属性,如ID,以执行您需要的任何区分。添加了此项,然后使用了一个函数。对我来说效果很好。
<ui-select-choices repeat="color in multipleDemo.availableColors | filter:$select.search"
refresh="refreshColors($select.search)"
refresh-delay="0">
{{color}}
</ui-select-choices>
<div ui-select ng-init="mySelect = $select"></div>
<button ng-click="search(mySelect.search)">Search</button>
$scope.$watch('mySelect.search', function(newVal){
alert(newVal);
});