How can I use Bootstrap Multiselect Dropdown in AngularJS

后端 未结 3 677
礼貌的吻别
礼貌的吻别 2020-12-15 18:31

I want to use Bootstrap Multiselect Dropdown http://davidstutz.github.io/bootstrap-multiselect/ in AngularJS. I hear that it\'s necessary to move it to Directive. But I thin

3条回答
  •  旧时难觅i
    2020-12-15 19:07

    If you don't need to create code that's very re-usable, it's actually not that complicated. The first step is to create a basic directive and to get the DOM element:

    angular.module('yourapp', [])
    
    .directive('multiselectDropdown', [function() {
        return function(scope, element, attributes) {
    
            element = $(element[0]); // Get the element as a jQuery element
    
            // Below setup the dropdown:
    
            element.multiselect({
                option1: 123,
                option2: "abcd",
                // etc.
            })
    
            // Below maybe some additional setup
        }
    }]);
    

    Basically, once you are within the directive, it's actually just regular jQuery or JS code.

    Then in your HTML code:

    
    

    You can also specify additional attributes on the DIV and get the values using the attributes parameter of the directive.

提交回复
热议问题