This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was 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
Description
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).