Vasiliy Shilov2013-04-26 12:48:44
Vasiliy Shilov, 2013-04-26 12:48:44

AngularJS select "nothing was selected, we have to insert the undefined item"?

The problem is this:
jsfiddle.net/agH3b/ is an empty item in the select.
How to get rid of it?
Fellow developers decided that github.com/angular/angular.js/blob/master/src/ng/d...
using css, an attempt to hide such an option in chrome did not result in anything, but in firefox, an interesting behavior
jsfiddle.net/6kZUB/ 1/ - just empty select
jsfiddle.net/6kZUB/2/ - select with empty option (height changed)
jsfiddle.net/6kZUB/3/ - select with empty option (in css display: none) (select with zero height)
jsfiddle .net/6kZUB/4/ - the same, but you can remove the option (even if removeChild is an empty option - the height is still 0, although it should be the same as in the first case)
jsfiddle.net/6kZUB/5/ - here option without css, you can also remove it (the 2nd case is replaced by the 1st)
jsfiddle.net/6kZUB/6/ final result of the 4th (should have been)

# lsb_release -a
No LSB modules are available.
Distributor ID:	Debian
Description:	Debian GNU/Linux 6.0.7 (squeeze)
Release:	6.0.7
Codename:	squeeze

$ google-chrome --version && firefox --version
Google Chrome 26.0.1410.63 
Mozilla Firefox 20.0

Answer the question

In order to leave comments, you need to log in

5 answer(s)
Vasiliy Shilov, 2013-05-08

Made a pull-request - github.com/angular/angular.js/pull/2590 . They said that people sometimes want an empty option with size>1 and did not accept, but they suggested a way (although it is not entirely logical).
i.e. use attributes
- for now this works for me as a solution

mayorovp, 2013-04-26

Or am I misunderstanding the problem?

maximr, 2013-05-02

In general, this is a cant of the 'select' directive, they need to check for the presence of the 'size' attribute, so if I were you, I would write them an issue, or make a pull-request, if they have not already done so.
So that it would be easier for other developers to live later.
The spec doesn't say anything about choosing a default element, but an empty element definitely shouldn't be there :)

Vasiliy Shilov, 2013-04-26

Apparently you will have to invent your own ngOptions Directive

1x1, 2013-04-26

option[value=""]:after, option[value="?"]:after {
    content: 'dummy';
    color: transparent;
option[value=""]:not(:last-child),option[value="?"]:not(:last-child) {
    display: none;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question