select with ng-init and filter on ng-option still shows empty line
-
21-12-2019 - |
Question
I am new to angularJS and I am struggling with a select issue. On my other selects I have managed to display what I wanted without any issue. But on this one I have a filter to flatten the array used for the list, since the elements I need are nested deeply in the array.
Here is the fiddle :JSFiddle
<select ng-model='selectedFunctionField' ng-init="selectedFunctionField = fields[0]" ng-options="field as field.display for field in fields|flatten" class="form-control"></select>
My issue is the empty line that I can't get rid off. I tried everything I found on SO : ng-init with a string, ng-init with an object, ng-init with a function, with a $scope variable, etc somehow something is wrong in my code but I can't see what...
Thanks for your help on this!
Solution
The nginit should be,
ng-init="selectedFunctionField = fields[0].columns[0]"
As you are filtering the data and returning columns.
Sample Demo: http://plnkr.co/edit/FF0hupHo0Qc2i2Ee5QVP?p=preview