0
I am working with angular and have the following select
<select ng-change="$ctrl.calculateDescount(partnerIndex,item)" ng-model="item.offerDiscountId" class="form-control" ng-if="item.view_offer">
<option value="">(Selecione uma Promoção)</option>
<option ng-repeat="offer in item.offers.data" ng-if="item.subtotal > offer.purchaseLimit" value="{{offer.id}}" ng-selected="item.idOffer == offer.id">{{item.idOffer}} {{offer.id}}</option>
</select>
Checking in the console the second option is with the Selected attribute inserted by the angular from the condition ng-selected
as it should. But it does not keep selected by displaying the "(Select a Promotion)".
<option ng-repeat="offer in item.offers.data" ng-selected="item.idOffer == offer.id" ng-if="item.subtotal > offer.purchaseLimit" value="30182" class="ng-binding ng-scope" selected="selected">30182 30182 </option>
I wonder if anyone has ever been through this type of problem and how it solved? since even with the attribute Selected is not respecting.
See: http://www.w3schools.com/tags/tryit.asp?filename=tryhtml_option_selected
– Marconi
what is the Marconi question even with the attribute Selected to indicate which should be selected it does not select.
– Miguel Batista
Your select is a little strange.. you’ve set yourself as a model in it
item.offerDiscountId
, so this must be the value selected inoption
, but there you are usingitem.idOffer
to mark the selected item. You have tried switching to this:ng-selected="item.offerDiscountId == offer.id"
?– Ricardo Pontual
That’s right, according to the documentation ngSelected does not interact with ngModel. It serves only as a selection indicator. the.idOffer item is the value that comes from the database after it is selected. the check is being done correctly and the angler is adding Selected="Selected" in the tag. But you are not holding selected after the page was loaded as I said https://docs.angularjs.org/api/ng/directive/ngSelected The change you suggested does not work either.
– Miguel Batista
@Miguelbatista The code you presented to us is correct, you can put the code of
controller
or put on a fiddle and also send a print of your inspection showing that there is aoption
attribute-riddenselected="selected"
. Maybe something is happening after the selection "event".– Lucas Fontes Gaspareto