THE SITUATION:
I need to insert flags inside the language select. I have searched in Google and StackOverflow but the solutions founded are not working for me.
THE CODE:
In the controller:
$scope.language_list = [{'name': 'english', 'url': 'https://raw.githubusercontent.com/stevenrskelton/flag-icon/master/png/16/country-4x3/gb.png'},{'name': 'italian', 'url': 'https://raw.githubusercontent.com/stevenrskelton/flag-icon/master/png/16/country-4x3/it.png'}];
In the view:
<select ng-model="language_selected">
<option ng-repeat="language in language_list" data-image="{{language.url}}" >{{language.name}}</option>
</select>
EXAMPLE:
http://jsfiddle.net/tcVhN/168/
THE QUESTION:
How can i insert images inside the angular select?
EDIT:
Here is the Plunker of the solution, cleaned up:
It's not possible, as
<option>
only supports text.You may have to roll your own drop-down control using complex HTML/CSS/JavaScript. How to do it may or may not be within the scope of your question.
Alternatively, you may use a non-repeating
background-image
and apply some padding on the text to achieve a similar effect. But if each<option>
is to have a unique image, your code is going to be polluted with astyle
attribute for every single<option>
. If you don't mind that, it's fine. Otherwise, roll your own somehow.Referred from : Adding images with option tag
Instead of inserting images you could generate css classes (from the language name or adding a new value only for that) and add the images as background images in your css (using sprites).
For the css sprites I usually use sass with compass.
The Answer:
Its simply not possible.
The permitted content of a
<option>
tag is Text with eventually escaped characters (likeé
). HTML isnt allowed.See the docs for more information.
The solution:
Make a custom Dropdown with CSS and HTML.
As other answers you can not use
<options>
to add an image, however you can use angular moduleui-select
to achieve what you want to do.Here is a demo with ui-select with your data.
Clean up the code and get what you need.
If you're not interested in search box override the CSS as,
DEMO
this is impossible with a native select element,
therfore, you need to design a selectbox using other html elements & css,
try this out: