ui-select: 如何以编程方式设置搜索字符串?
ui-select: how to set the search string programmatically?
如何从我的代码中设置搜索字符串(即 $select.search
)?当然,应该根据新的搜索字符串应用选项过滤器。
像下面这样尝试。
HTML:
<ui-select id="mySelect">
JS:
angular.element('#mySelect').controller('uiSelect').search = "<new-search-string>";
您可以使用 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";
}]);
如何从我的代码中设置搜索字符串(即 $select.search
)?当然,应该根据新的搜索字符串应用选项过滤器。
像下面这样尝试。
HTML:
<ui-select id="mySelect">
JS:
angular.element('#mySelect').controller('uiSelect').search = "<new-search-string>";
您可以使用 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";
}]);