0

I am trying to get select2 library working with AngularJS select.

I am created a small jsfiddle with the same option values which i am using in my project.

But the select2 seems to be working wrongly. For Eg: When I select index 2, it shows value from index 3. For the first tome it works fine, but from the second time it breaks.

JSFiddle Link

Has anyone faced this issue till now?

georgeawg
  • 48,608
  • 13
  • 72
  • 95
Nagendra Singh
  • 577
  • 1
  • 7
  • 24
  • The event handlers added by jQuery fight the event handlers added by the AngularJS directives. Use [tag:angular-ui-select] - AngularJS native version of Select2 and Selectize – georgeawg May 20 '18 at 14:27
  • can you please share an example of angularjs-select? – Nagendra Singh May 20 '18 at 14:30
  • https://github.com/angular-ui/ui-select – georgeawg May 20 '18 at 14:31
  • I agree with @georgeawg to use angular plugins libs. But sometimes you just don't get exact same library in angular. So considering that, I've posted the working solution. You can check if it works or you can always use angular-ui set of libraries like ui-bootstrap, etc – Shantanu May 20 '18 at 14:34

1 Answers1

0

You're using way too older version of angularjs. At least use 1.4.x There are many breaking changes after 1.2. So, at least from 1.4 it's quite stable. I've created following plunker example from your jsfiddle code. It's working as expected.

Plunker Example

Shantanu
  • 3,483
  • 2
  • 17
  • 20
  • This works. But I dont understand why @georgeawg wrote "event handlers added by jQuery fight the event handlers added by the AngularJS directives". It shouldn't have worked for 1.4 either. – Nagendra Singh May 20 '18 at 14:47
  • @NagendraSingh What he said is correct. but angularjs doesn't have problem with jquery. They recommended not to use but if you add the lib before angularjs in index.html then angularjs itself starts using the external jquery. But very old version of angularjs has problem with recent versions of jquery. – Shantanu May 20 '18 at 14:54