bootstrap-select 中的 Ng 选项不起作用
Ng-options in bootstrap-select doesn't work
我想将 multi select 添加到我的应用程序,但是当我尝试从控制器加载数据时 select 不起作用。我在 select 中使用了 ng-options 和 ng-repeat,但两者都不起作用。 My plugin: bootstrap-select
您正在 AngularJS 中使用 jQuery 插件,您可以通过调用与元素绑定的指令中的函数来使用它,如下所示:
HTML:
<select class="selectpicker" bootstrap-selectpicker data-ng-model="modelValue" multiple="" data-actions-box="true">
<option>Mustard</option>
<option>Ketchup</option>
<option>Relish</option>
</select>
指令:
app.directive('bootstrapSelectpicker'), function(){
var bootDirective = {
restrict : 'A',
link: function(scope, element, attr){
$(element).selectpicker();
}
};
return bootDirective;
});
但我建议使用基于 Angularjs 的下拉菜单,请查看以下插件。
http://isteven.github.io/angular-multi-select/#/main
http://angular-ui.github.io/ui-select/
http://ngmodules.org/modules/angular-bootstrap-multiselect
https://github.com/dotansimha/angularjs-dropdown-multiselect
希望这对您有所帮助:)
我在 option
标签上使用 ng-repeat
。对我来说 运行 每次我获取新数据时,以下函数就可以完成工作:
function selectPickerRefresh() {
$timeout(function() {
$scope.$digest();
$('.selectpicker').selectpicker('refresh');
});
}
我想将 multi select 添加到我的应用程序,但是当我尝试从控制器加载数据时 select 不起作用。我在 select 中使用了 ng-options 和 ng-repeat,但两者都不起作用。 My plugin: bootstrap-select
您正在 AngularJS 中使用 jQuery 插件,您可以通过调用与元素绑定的指令中的函数来使用它,如下所示:
HTML:
<select class="selectpicker" bootstrap-selectpicker data-ng-model="modelValue" multiple="" data-actions-box="true">
<option>Mustard</option>
<option>Ketchup</option>
<option>Relish</option>
</select>
指令:
app.directive('bootstrapSelectpicker'), function(){
var bootDirective = {
restrict : 'A',
link: function(scope, element, attr){
$(element).selectpicker();
}
};
return bootDirective;
});
但我建议使用基于 Angularjs 的下拉菜单,请查看以下插件。
http://isteven.github.io/angular-multi-select/#/main
http://angular-ui.github.io/ui-select/
http://ngmodules.org/modules/angular-bootstrap-multiselect https://github.com/dotansimha/angularjs-dropdown-multiselect
希望这对您有所帮助:)
我在 option
标签上使用 ng-repeat
。对我来说 运行 每次我获取新数据时,以下函数就可以完成工作:
function selectPickerRefresh() {
$timeout(function() {
$scope.$digest();
$('.selectpicker').selectpicker('refresh');
});
}