12

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!!

Oc Chuoj Dau
  • 649
  • 2
  • 8
  • 14
  • Where have you written the code to watch `$viewContentLoaded`? In your controller or is it in a directive? – callmekatootie Jun 05 '13 at 06:57
  • I wrote it in Controller. http://paste.laravel.com/v5k . It worked. But when putting ng-repeat into it (view section), then ng-repeat is disabled. Tks @callmekatootie – Oc Chuoj Dau Jun 05 '13 at 07:11
  • Why don't you move the code into a directive? AFAIK, jQuery based DOM manipulation should be strictly kept out of the controllers. http://docs.angularjs.org/misc/faq#commonpitfalls - this section describes it in detail. Move the code from the controller to a directive and then try. Also, have you tried putting the above code inside `$scope.$apply()`? – callmekatootie Jun 05 '13 at 08:36
  • @callmekatootie It seems to be difficult to move to directive :| – Oc Chuoj Dau Jun 05 '13 at 17:13
  • Please select the answer for your question. I am looing for the Solution for this question. – Dinesh Apr 17 '14 at 14:50
  • Checkout : [multiselectable-dropdown-checkboxes-using-angular-js](https://stackoverflow.com/a/36694996/2757635) – rhitz Jul 29 '17 at 07:04

4 Answers4

10

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"}];
Aleksey
  • 109
  • 1
  • 5
  • Verified that it works in both Firefox and Chrome under both GNOME/Mint 14 and whatever version of Windows I have to use at work. – Michael Scheper Jul 09 '14 at 08:46
6

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.

  • 2
    Your solution is working on chrome for me but not with firefox :/ – Vincenzo Oct 08 '13 at 21:04
  • @user2598687 if i could upvote ten times, i'd do it. thanks in particular for the fiddle, for me it came down to certain versions of bootstrap and bootstrap-ui. – tcmb Nov 06 '13 at 18:13
  • 1
    @toregua is correct, it does not 'check' the selected items in Firefox (latest version). Is there a work-around? – Larry Eitel Jan 01 '14 at 21:13
0

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]));
}
Brendan W
  • 3,303
  • 3
  • 18
  • 37
0

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

JEuvin
  • 866
  • 1
  • 12
  • 31