Anik Anik - 3 months ago 17
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

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 
</div>

Also @Satpal answer is really helpfull

Comments