2

I am using Select2 with its angular interface for a select form like

<select ui-select2 ng-model='thing' data-placeholder='Options' id='form1>
  <option value=''></Option>
  <option value='1'>Option 1</Option>
  <option value='2'>Option 2</Option>

In my controller, I have the line

$('#form1').select2();

to enable Select2. However, when I run this, I get the error

query function not defined for Select2 s2id_form1

and nothing shows up in the input box. I've tried to put in a query function in the initializer, but nothing is working. When I do define a query function, like

$('#form1').select2({query: function (query) {return 0;}});

It says that I can't put a query option in a select form. How can I fix this error?

1 Answer 1

2

Well you're bypassing the AngularUI Select2 code by invoking $('#form1').select2() - that's just the regular jQuery select2 method.

You want to setup your select2 options within an object scoped to your controller

$scope.select2setup = {...}

Then in your html

<select ui-select2="select2setup"....>

It's all pretty well documented @ https://github.com/angular-ui/ui-select2

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.