【问题标题】:ui-select: how to set the search string programmatically?ui-select:如何以编程方式设置搜索字符串?
【发布时间】:2016-01-02 22:57:08
【问题描述】:

如何从我的代码中设置搜索字符串(即$select.search)?当然,选择的过滤器应该根据新的搜索字符串应用。

【问题讨论】:

    标签: angularjs ui-select angular-ui-select


    【解决方案1】:

    您可以使用 ui-select 元素上的 ng-init 指令来获取 ui-select 控制器:

    <div ng-controller="MyCtrl">
        <ui-select ng-init="$parent.myUiSelect = $select" ...>
        ...
        </ui-select>
    </div>
    

    然后在你的控制器中:

    app.controller('MyCtrl', ['$scope', function($scope) {
        $scope.myUiSelect.search = "new value";
    }]);
    

    【讨论】:

      【解决方案2】:

      尝试如下。

      HTML:

      <ui-select id="mySelect">
      

      JS:

      angular.element('#mySelect').controller('uiSelect').search = "<new-search-string>";
      

      【讨论】:

        猜你喜欢
        • 2011-05-02
        • 2012-11-30
        • 1970-01-01
        • 1970-01-01
        • 2016-06-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-08-14
        相关资源
        最近更新 更多