class jfMultiDropdownController {
    constructor($scope, $filter) {

        this.$scope = $scope;

        this.filter = $filter('filter');
        this.opened = false;

        this.handleOutsideClick();

        this.$scope.$watch('jfMultiDropdown.items', (newVal, oldVal) => {
            if (newVal) {
                this.sortItems();
            }
        });
        this.$scope.$watch('jfMultiDropdown.dropdownOpened', (val) => {
            if (val === true) {
                if (!this.items) return;
                this.opened = true;
                this.filterText = '';
            }
            else if (val === false) {
                this.opened = false;
                this.filterText = '';
            }
            else {

            }
        });

    }

    handleOutsideClick() {
        let handler = (e) => {
            let outside = !$(e.target).parents('.jf-multi-dropdown').length
            if (outside) {
                this.opened = false;
                this.sortItems();
            }
            this.$scope.$apply();
        };
        $(document).on('click',handler);
        this.$scope.$on('$destroy',() => {
            $(document).off('click', handler)
        })
    }

    onClick() {
        if (this.disabled !== true) {
            if (!this.items) return;
            this.opened = !this.opened;
            if (!this.opened) this.sortItems();
            this.filterText = '';

        }

    }
    onSelection() {
        if (this.onChange) this.onChange();
    }
    getSelectedCount() {
        let selected = _.filter(this.items, (item) => item.isSelected);
        return selected.length;
    }

    sortItems() {
        if (!this.items) return;
        let selected = _.sortBy(_.filter(this.items, (item) => item.isSelected), 'text');
        let unSelected = _.sortBy(_.filter(this.items, (item) => !item.isSelected), 'text');
        this.lastSelectedIndex = selected.length-1;
        let combined = selected.concat(unSelected);
        this.items.splice.apply(this.items, [0,this.items.length].concat(combined));
    }
    selectAll() {
        this.filter(this.items, this.filterText).forEach((item)=>{item.isSelected = true;})
        this.onSelection();
    }
    unSelectAll() {
        this.filter(this.items, this.filterText).forEach((item)=>{item.isSelected = false;})
        this.onSelection();
    }

}

export function jfMultiDropdown() {
    return {
        controller: jfMultiDropdownController,
        controllerAs: 'jfMultiDropdown',
        bindToController: true,
        scope: {
            title: '@',
            filterPlaceholder: '@',
            noItemsMessage: '@',
            items: '=',
            disabled: '=?',
            onChange: '&?',
            dropdownOpened: '='
        },
        templateUrl: 'directives/jf_multi_dropdown/jf_multi_dropdown.html'
    }
}
@@ -771,24 +771,141 @@
 %7D);%0A%0A    %7D%0A%0A
+    sendOpenStateChange() %7B%0A        if (this.onOpenStateChange) this.onOpenStateChange(%7Bopened:this.opened%7D);%0A    %7D%0A%0A
     handleOu
@@ -911,32 +911,32 @@
 utsideClick() %7B%0A
-
         let hand
@@ -1082,32 +1082,76 @@
 opened = false;%0A
+                this.sendOpenStateChange();%0A
                 
@@ -1458,32 +1458,32 @@
 .items) return;%0A
-
             this
@@ -1506,16 +1506,56 @@
 opened;%0A
+            this.sendOpenStateChange();%0A
         
@@ -2931,24 +2931,61 @@
 ange: '&?',%0A
+            onOpenStateChange: '&?',%0A
             

Add event for opened state change