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

6
  • Where have you written the code to watch $viewContentLoaded? In your controller or is it in a directive? Commented Jun 5, 2013 at 6:57
  • I wrote it in Controller. paste.laravel.com/v5k . It worked. But when putting ng-repeat into it (view section), then ng-repeat is disabled. Tks @callmekatootie Commented Jun 5, 2013 at 7:11
  • Why don't you move the code into a directive? AFAIK, jQuery based DOM manipulation should be strictly kept out of the controllers. 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(<code here>)? Commented Jun 5, 2013 at 8:36
  • @callmekatootie It seems to be difficult to move to directive :| Commented Jun 5, 2013 at 17:13
  • Please select the answer for your question. I am looing for the Solution for this question. Commented Apr 17, 2014 at 14:50

4 Answers 4

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"}];
Sign up to request clarification or add additional context in comments.

1 Comment

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

3 Comments

Your solution is working on chrome for me but not with firefox :/
@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.
@toregua is correct, it does not 'check' the selected items in Firefox (latest version). Is there a work-around?
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]));
}

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.