I'm working on a directive that wraps multiselect jQuery plugin. My goal is to convert the following HTML into a dynamic multiselect:
<select multiselect multiple ng-model="selected">
<option>Static option 1</option>
<option>Static option 2</option>
<option ng-repeat="value in values">{{value}}</option>
</select>
Notice that options can be added directly or using ng-repeat to iterate over dynamic options.
Here's how I wrote the directive:
app.directive('multiselect', function () {
return {
restrict: 'A',
scope: {
model: '='
},
transclude: true,
require: 'ngModel',
link: function (scope, element, attrs, controller, transclude) {
transclude(function (clone) {
element.append(clone);
$(element).multiselect();
});
}
};
});
The problem is that while the directive works and replace HTML with the jQuery multiselect plugin, it displays only options provided statically. Options created using ng-repeat aren't displayed by the plugin, even though they can be seen in the HTML source rendered by Angular. It seems as if the transclude clone is appended to the element after multiselect is created by the plugin.
Here's the JSFiddle that reproduces this problem.
Is my understanding correct? What may be the cause of this behavior?