I am trying to create an angular directive that will initialise the select2, this directive will be used in select tag as below
<select ng-model="add.doctype" class="form-control select2" select2 append-to-body ng-options="x.tipe for x in ::Types">
<option value=""></option>
</select>
And the directive is
(function() {
'use strict';
angular.module('myapp.theme')
.directive('select2', select2);
function select2() {
return {
$(".select2").select2({ theme: "bootstrap" });
};
}
})();
it gave an error in console Unexpected string pointed to $(".select2").select2({ theme: "bootstrap" });, did i miss something there?
return { ... }indicates you are returning an object but it has no keys. Try `return { link: function(scope, element) { jQuery(element[0]).select2({theme: 'bootstrap'}) } }use strictdo not solve the problem.