问题
I used Bootstrap Multiselect Dropdown http://davidstutz.github.io/bootstrap-multiselect/ & embed into the sub-template of AngularJS & let it run with the following function:
$scope.$on('$viewContentLoaded', function () {
$(document).ready(function() {
$('#example27').multiselect({
includeSelectAllOption: true
});
});
});
I continued using ng-repeat to print the inside options of this input select:
<select id="example27" multiple="multiple">
<option ng-repeat="list in lists" value="{{list.id}}">{{list.name}}</option>
</select>
But when ng-repeat is in this input select, it did not work & didn't print any data. Anybody knows how to solve this problem, please help me!!
回答1:
If you use bootstrap-multiselect you should use ng-options attribute, like in @user2598687 answer. Here version of fiddle that works with firefox: click me to jsfiddle
<select class="multiselect" data-placeholder="Select Products"
ng-model="productSelection" ng-options="item.id as item.name for item in Products"
multiple="multiple" multiselect-dropdown >
$scope.Products = [{id:1,name:"Apple"}, {id:2,name:"Banana"}, {id:3,name:"Carrort"}, {id:4,name:"Dart"}];
回答2:
you may try to take a look at the issue, https://github.com/davidstutz/bootstrap-multiselect/issues/128 and the js fiddle, http://jsfiddle.net/58Bu3/1/ as both are related to use of angular js with bootstrap-multiselect. Here is how I have used it in creating the fiddle.
<select class="multiselect" data-placeholder="Select Products"
ng-model="productSelection" ng-options="item as item for item in Products"
multiple="multiple" multiselect-dropdown >
</select>
<p>Selection: {{productSelection}}</p>
The example is a working one, so go ahead and try it.
回答3:
I just dealt with this issue!! Instead of trying to use ng-repeat, you can add options dynamically with something like this:
var topicSelect = document.getElementById("topic-select");
for (topic in scope.topicList) {
topicSelect.add(new Option(scope.topicList[topic], scope.topicList[topic]));
}
回答4:
I been looking for a multiselect dropdown myself. I eneded up working this solution myself using Long2Know. I even got the multiselect in a UI Modal, which was my original goal.
var myApp = angular.module('myApp', ['long2know', 'ui.bootstrap']);
myApp.controller('testCtr', function($scope, $uibModal) {
$scope.test = function() {
$scope.colors = [{
name: 'black'
}, {
name: 'white'
}, {
name: 'red'
}, {
name: 'blue'
}, {
name: 'purple'
}, {
name: 'pink'
}, {
name: 'brown'
}, {
name: 'yellow'
}];
$uibModal.open({
template: "<multiselect class='input-xlarge multiselect' ng-model='myColor' options='color.name for color in colors' multiple='true' required enable-filter='true' filter-placeholder='Filter stuff..'></multiselect>",
controller: 'newCtrl',
resolve: {
colors: function() {
return $scope.colors;
}
}
});
}
});
myApp.controller('newCtrl', function($scope, colors) {
$scope.colors = colors;
});
Plunker
来源:https://stackoverflow.com/questions/16933324/angularjs-ng-repeat-in-bootstrap-multiselect-dropdown