So, I have an Angular view that has the following markup:
<select id="ddlHandheldIds" name="ddlHandheldIds" class="form-control" ng-model="vm.handheldPayment.handHeldId" ng-options="id as id for id in vm.handheldKeys track by id" required title="select hand held id"> <option value="">select hand held id</option> </select>
When loading the vm.handheldKeys page, vm.handheldKeys array with two values ββis found [0,24] .
When the page loads, the displayed HTML looks like this (read tab):
<select id="ddlHandheldIds" name="ddlHandheldIds" class="form-control ng-dirty ng-touched ng-valid-parse ng-valid ng-valid-required" ng-model="vm.handheldPayment.handHeldId" ng-options="id as id for id in vm.handheldKeys track by id" required="" title="select hand held id"> <option value="" class="">select hand held id</option> <option value="0" label="0">0</option> <option value="24" label="24">24</option> </select>
This, of course, is what you expect.
Now, through some business logic, after the user interacts with the page, there is a function that combines the vm.handheldKeys array. So, let's say the code is as follows:
vm.handheldKeys.splice(0,1);
Now I get the following rendered HTML (pay attention to the first option):
<select id="ddlHandheldIds" name="ddlHandheldIds" class="form-control ng-dirty ng-touched ng-valid-parse ng-valid ng-valid-required" ng-model="vm.handheldPayment.handHeldId" ng-options="id as id for id in vm.handheldKeys track by id" required="" title="select hand held id"> <option value="? string:0 ?"></option> <option value="" class="">select hand held id</option> <option value="24" label="24">24</option> </select>
What is the best way to remove an element from an array without creating this extra option? This is mistake?
I am debugging my JavaScript in WebStorm and, of course, there is only one element in the array after splicing.
Thanks.
UPDATE:
I also tried to add a filter and set the parameter source to the filter, but I still get the same result.
vm.filteredHandheldKeys = function() { var ids = handheldPayments.map(function(pmt) { return pmt.handHeldId; }); if (!vm.handheldKeys) return; return vm.handheldKeys.filter(function(key) { return ids.indexOf(key) == -1; }); };
UPDATE 2:
Just FYI if I were to perform
vm.handheldKeys.splice(1,1);
Now the selection option:
<option value="? string:24 ?"></option>
Perhaps this is due to this form, in which the selection field is located, in the modal? Maybe the modal will not display correctly correctly?