2

Ever since I upgraded from AngularJS 1.3.15 to 1.4.8 I'm getting an empty option added to all my select2 uses.

I've tried what is suggested here: Why does AngularJS include an empty option in select? and in other questions, but couldn't make it work for me.

Here is a plunkr of my issue: http://plnkr.co/edit/zrYCDbtSVHNt3tRZsQza?p=preview

As you can see, an empty option is added, after selecting any of the 2 values there, the empty option disappears.

The relevant HTML:

<select ui-select2 ng-model="cqData.dataObjects.Mode.Value">
    <option value="structured" localize>Structured Query</option>
    <option value="advanced" localize>Advanced Query</option>
</select>

P.S. I know ui-select2 is deprecated, but its an existing project and I'm unable at the moment to upgrade it.

Community
  • 1
  • 1
AlexD
  • 4,062
  • 5
  • 38
  • 65
  • if you update select2 and ui-select2 (not to ui-select )it works http://plnkr.co/edit/8WUPObf57WjhcY5ZbEfV?p=preview . – koox00 Dec 27 '15 at 14:23
  • @koox00 Awesome! You know how to fix the errors it throws to the console? – AlexD Dec 27 '15 at 15:03
  • @koox00 it gives me a lot more errors when I update the references in my project, including some modals that stop working, probably it all comes down to solving the error it throws in the plunkr though – AlexD Dec 27 '15 at 15:18
  • 1
    I've updated my plunker using angular 1.4.7 doesn't have that blank option. but I think if you are going to update you have to update everything – koox00 Dec 27 '15 at 15:58
  • @koox00 thanks! Seems I'll be stuck with 1.4.7 until I have time to upgrade to ui-select library. – AlexD Dec 30 '15 at 08:21

1 Answers1

0

Try to set default value in controller like this:

$scope.cqData.dataObjects.Mode.Value = $scope.cqData.dataObjects.Mode[0].Value;

Its working fine.

Vishal Rajole
  • 1,504
  • 1
  • 13
  • 19
  • How does that answer my question? It isn't relevant how I initialize the ngModel, as long as I do. – AlexD Dec 30 '15 at 08:19