Skip to content

Instantly share code, notes, and snippets.

@dancras
Last active April 27, 2020 14:59
Show Gist options
  • Save dancras/5191040 to your computer and use it in GitHub Desktop.
Save dancras/5191040 to your computer and use it in GitHub Desktop.
'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');
});
}
};
});
@mikila85
Copy link

example?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment