1

Here is my code:

<select id="storeSelectBox" ng-model="model.store" ng-options="store.name for store in model.stores[model.retailer.shortName]" ng-change="retailerSelected()"></select>

My issue is following: since 'store.name' is not mandatory it can be emtpy and select shows empty items. Is there any possibility to get 'store.shortName' only when 'store.name' is empty? Would be great to modify somehow ng-options expression without touching controller. Thanks in advance for help.

1
  • show both then use ng-if to leverage showing only one? Commented Oct 4, 2017 at 9:01

1 Answer 1

2

You can try this,

<select id="storeSelectBox" ng-model="model.store" ng-change="retailerSelected()">
    <option ng-repeat="store in model.stores[model.retailer.shortName]" ng-value="store">
        <span ng-if="store.name">{{store.name}}</span>
        <span ng-if="!store.name">{{store.shortName}}</span>
    </option>
</select>

It will show shortName if name is empty, still entire store object will be assigned to model.store

Sign up to request clarification or add additional context in comments.

2 Comments

It works partially. It shows items as expected, but when I will choose any option it's not shown in select as a choosen.
It should just work fine, you maybe changing the value of model.store in ng-change function

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.