Angular1
I have implemented the code snippet below to automatically select the first value in the result set if it is not already selected.
Take a look at "$index==0?true:false"
HTML
<li ng-repeat="address in addresses | filter:vm.addressSearch">
<div class="checkbox">
<input type="radio" name="address-list" id="address-{{address.addressId}}"
ng-click="vm.setAddress( address.addressId )"
ng-checked="address.addressId === vm.cart.addressId || $index==0?true:false">
</div>
JS Validation
vm.setAddress = function( addressId ) {
vm.cart.addressId = addressId;
updateShippingValid();
};
function updateShippingValid() {
vm.shippingValid = angular.isNumber( vm.cart.addressId ) && ( vm.cart.addressId !== 0 ) && angular.isString( vm.cart.shipMethod );
}
The first radio button for addresses will now be pre-selected upon loading, but my validation does not initially recognize it as selected, requiring an additional click. Is there a specific reason for this behavior?
Thank you