Fix selection of duplicated items in form select elements with AngularJs directive
At a customer we have e.g. a country list in a select form element. It’s special because it has an option group called “top countries”. Inside the list are duplicates, that are listed in the option group “all countries” to. The browser tends to select the latest matching element – which in this special case makes no sense.
Here is a directive that ensures the first matching element is selected: