I\'ve followed this great tutorial (link) for Chosen and Angular (code is pretty much same)
Here is my directive:
app.angularModule.directive(\'chose
More expanded version of comment to previous solution.
Same as author, in HTML markup I provide source collection like chosen="vm.myCollection", actually parsing ng-options or ng-repeat property with regexp is better, maybe later.
In contrast with OP, I use $watchCollection for an array, and call unwatches when scope is about to destroy.
(function () {
'use strict';
angular.module('common.directives').directive('chosen', enterPressDirective);
function enterPressDirective() {
return {
restrict: 'A',
link: function (scope, elm, attrs) {
var unwatchModel = scope.$watch(attrs.ngModel, function () {
elm.trigger('chosen:updated');
});
var unwatchSource = scope.$watchCollection(attrs.chosen, function () {
elm.trigger('chosen:updated');
});
elm.chosen();
scope.$on('$destroy', function () {
unwatchModel();
unwatchSource();
});
}
};
}
}());