0

I have this line

<select ng-options="item.subItem as item.label for item in items track by item.id" ng-model="selected"></select>

everything worked fine, but now in answer from server comes an indeterminate value for item.label. Sometimes.

Is it possible to add a condition in this line if this field does not exist then apply another? Or it is impossible for ng-options? like this:

<select ng-options="item.subItem as item.label || item.id  for item in items track by item.id" ng-model="selected"></select>

1 Answer 1

2

Absolutely. You are almost correct just wrap the expression in parenthesis.

ng-options="item.subItem as (item.label || item.id) for item in items track by item.id"

Here's a working fiddle.

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

Comments

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.