Conditional operation in ionic


#1

We need to display Create Activity if id is null otherwise display Update Activity.
We are trying
"

({{editid}}!=’’)?“Create Activity” :“Update Activity”

" but it is not working.
Please advise?

#2

Check out:
https://docs.angularjs.org/api/ng/directive/ngIf

<span data-ng-if="(editid != '')" >Create Activity</span>
<span data-ng-if="(editid == '')" >Update Activity</span>

By adding the above lines you will achieve what you asked for :wink:


#3
{{editid ? 'Update Activity' : 'Create Activity'}}

#4

@m13z That’s also a possibility :slight_smile: Seems nicer to me in this situation.


#5

@iwantwin I was actually writing a similar solution to yours, but for just a string it’s simpler to use an expression.


#6

Very true, and both solutions are very worth to mention to increase topic starter’s knowledge :slight_smile: