Dean Jason
Dean Jason

Reputation: 105

Or operator with ng-model expression

<input placeholder="{{a}} || zero">

I want to set the placeholder to become 'zero' if the {{a}} is null but that isn't work, it displayed || zero instead.

Upvotes: 1

Views: 288

Answers (1)

valverde93
valverde93

Reputation: 1698

The right way:

<input placeholder="{{ a || 'zero' }}">

The first step is: Angular calculates the result of the expression inside {{ }} - a || 'zero'

The second step is: Angular puts the result to the placeholder

In your variant:

The first step is: Angular calculates the result of the expression inside {{ }} - a

The second step is: Angular puts the result to the placeholder

The third step is: HTML appends || zero as string to the placeholder

Upvotes: 5

Related Questions