Reputation: 7022
I want to know how to make the select as
of the ng-options
attribute interchangeable, I mean, I want it to evaluate if display one or another value; there's an array of jsons that has the following keys:
[
{id: 1, name: 'christmas', alias: 'xmas'},
{id: 2, name: 'new year', alias: null}
]
So, what I want is to display name
if alias
is null, but if alias
is not null, then display alias
, what do I need to add to ng-options
:
ng-options="f as f.name for f in vm.festivities"
Upvotes: 0
Views: 456
Reputation: 1
Try this:
ng-options="f as f.alias && (f.name === null || f.name) for f in vm.festivities"
because you want f.alias
to be not null
and other expression can be null
Upvotes: 0
Reputation: 691715
Use
ng-options="f as (f.alias || f.name) for f in vm.festivities"
In JavaScript, a || b
evaluates to the first truthy operand (or the last one if none of them is truthy)
Upvotes: 3