【问题标题】:How to use ui-select2 events如何使用 ui-select2 事件
【发布时间】:2014-07-01 10:21:00
【问题描述】:

我正在使用 ui-select2,如文档中所示:

<select ui-select2="{ allowClear: true}" ng-model="select2">
    <option value="one">First</option>
    <option value="two">Second</option>
    <option value="three">Third</option>
</select>

我想在像 select2-open, select2-opening or select2-close 这样的事件上调用控制器上的一些函数:

$scope.myFunction = function(){
 alert("Hello");
}

我该怎么做?

【问题讨论】:

  • 您找到了如何观看触发事件的答案吗?我对“select2-open”特别感兴趣。我也发现了这个问题,但没有帮助我解决我的问题stackoverflow.com/questions/18968376/…
  • 你试过 angular-ui-select 吗?这是一个纯粹的角端口。
  • 我前段时间遇到过这个问题,但我还没有尝试过。如果您尝试过,您认为它回答了我的问题吗?
  • @Sulthan 问题是,angular-ui-select 仍在大力开发中,它缺少许多功能。查看路线图github.com/angular-ui/ui-select/wiki/Roadmap,看看您是否满足您的要求并且不需要完全实现的 select2 端口。

标签: angularjs jquery-select2 ui-select2 angularjs-select2


【解决方案1】:

我是通过向 select2 元素添加另一个指令来实现的,您可以在其中收听事件。

HTML:

<select ui-select2="{allowClear: true}" ng-model="select2" my-directive>
    <option value="one">First</option>
    <option value="two">Second</option>
    <option value="three">Third</option>
</select>

指令:

myApp.directive('myDirective', function() {
    return {
        link: function(scope, element) {
            element.on('select2-loaded', function() {
                // do cool stuff
            });
        }
    }
});

【讨论】:

  • 试过这个方法,对我不起作用。您还记得您为此使用的 AngularJS / UI-select 版本吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-01-07
  • 1970-01-01
相关资源
最近更新 更多