Anik Anik - 1 year ago 74
Javascript Question

Handling boolean data returned by JSON string using angular expression

I am reading data from a JSON string using angular and playing around with my app at the moment.

Task Status : {{task.completed}} // displays true or false

I want to achieve something like this:

if(task.completed == true) print "completed";
else "print Not completed"

How can this be done in an angular expression?

Answer Source

You can use ng-if or ng-show for it

<div> Task Status : 
 <span ng-if="task.completed">{{"completed"}}</span 
 <span ng-if="!task.completed">{{"print Not completed"}}</span 

Also @Satpal answer is really helpfull

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download