Last active
April 27, 2020 14:59
-
-
Save dancras/5191040 to your computer and use it in GitHub Desktop.
A directive to use this https://github.com/davidstutz/bootstrap-multiselect
with this http://angularjs.org/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
angular.module('angularTrainingApp') | |
.directive('multiple', function () { | |
return { | |
scope: true, | |
link: function (scope, element, attrs) { | |
element.multiselect({ | |
// Replicate the native functionality on the elements so | |
// that angular can handle the changes for us. | |
onChange: function (optionElement, checked) { | |
optionElement.removeAttr('selected'); | |
if (checked) { | |
optionElement.attr('selected', 'selected'); | |
} | |
element.change(); | |
} | |
}); | |
// Watch for any changes to the length of our select element | |
scope.$watch(function () { | |
return element[0].length; | |
}, function () { | |
element.multiselect('rebuild'); | |
}); | |
// Watch for any changes from outside the directive and refresh | |
scope.$watch(attrs.ngModel, function () { | |
element.multiselect('refresh'); | |
}); | |
} | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
example?