AngularJS ng-repeat in Bootstrap multiselect dropdown

霸气de小男生 提交于 2019-12-05 00:34:12

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"}];

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.

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]));
}

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!