When using ng-options on a single select after selecting an option attempting to select the last option will throw this error: "Uncaught TypeError: Cannot set property 'selected' of undefined"
See original GitHub issueIt’s an off by 1 error. ng-options is generating the list with n+1 options(the +1 being an empty option). The solution is to watch the select.length and on change throw an updated call.
Here is the fix, jam it in the linker function:
scope.$watch(function(){
return element[0].length;
}, function(newvalue, oldvalue){
if (newvalue !== oldvalue) {
element.trigger("chosen:updated");
}
});
Issue Analytics
- State:
- Created 10 years ago
- Reactions:1
- Comments:14 (2 by maintainers)
Top Results From Across the Web
AngularJS ng-options selecting default value after selecting ...
vm.modelObject.selectedOption will pass an isDefined check -- because it's defined, but with no value assignment.
Read more >ngOptions - AngularJS: API
When an item in the <select> menu is selected, the array element or object property represented by the selected option will be bound...
Read more >Fix Cannot Set Property of Null Error in JavaScript - YouTube
Check us out at https://www.skillforge.com The " cannot set property of null " error is a very common JavaScript issue that you may...
Read more >A brief walk-through of the ng-options in AngularJS
The AngularJS documentation for 'select' says to use ng-options instead of ng-repeat in this scenario. The reason behind is, option element ...
Read more >How to Fix 'cannot set properties of null' Errors in JS - Webtips
Lear what is the root cause and how you can fix 'Uncaught TypeError: Cannot set properties of null (setting 'value')' errors in JavaScript....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @climbican, try add an empty
<option></option>
. It should work as well.https://ashuthinks.wordpress.com/2016/02/18/chosen-js-dropdown-last-select-issue/