Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

select ngModel fails to pick empty option when expression is undefined (but has null in the middle of chain) #5442

Closed
astral303 opened this issue Dec 16, 2013 · 3 comments

Comments

@astral303
Copy link

If I have an empty option in SELECT with:

ng-model="obj.item"
$scope.obj = {}

Then ng-model correctly picks the empty variable. However, if the object is null, then the empty option is not picked:

ng-model="obj.item"
$scope.obj = null

I traced this down to https://github.com/angular/angular.js/blob/master/src/ng/directive/select.js#L256 -- it checks for undefined ONLY, but in the 2nd case, $scope.$eval("obj.item") comes back as null due to #2249.

Demo:
http://plnkr.co/edit/RbPnV3d3LHhkyCoiTsGo?p=info

I think the fix is to either A) fix select.js to treat null as an empty value or B) fix #2249 to return undefined if the entire expression chain cannot be evaluated.

I think A is best, since null is not a real value anyway (not the kind of value you could be selecting from a select box).

@astral303
Copy link
Author

Reproducing using Angular 1.2.4.

Here's a workaround using a directive: https://gist.github.com/astral303/8007019

@IgorMinar
Copy link
Contributor

we should get #2249 fixed

@IgorMinar
Copy link
Contributor

I'm going to mark this as dupe of #2249 and close it. if fixing that issue doesn't solve this issue please create a new issue.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants