Konrad the n00b Konrad the n00b - 1 month ago 5x
AngularJS Question

Format column value in ng-repeat angular

Im new to angular and I have a problem. I have a value thats 1 or 0 in a value in the array.
When I show these in the table I would like to show No if its a 0 and Yes if its 1.

I have this table and Active is showing 1 or 0.

<table class="table table-striped table-bordered" id="tableA">
<tr ng-repeat="item in dRows">

How to could I make it Yes and No instead?
please help, thanks


You can use the conditional operator (?:) if you are using Angular version 1.1.5 or later:

<td>{{(item.Active == 1 ? 'Yes':'No')}}</td>

Another way is to use filter. First, add the filter to the current module

app.filter('YesNo', function () {
    return function (num) {
        return num === 1 ? 'Yes' : 'No';

Then use it as this

 <td>{{(item.Active | YesNo)}}</td>