Konrad the n00b
Konrad the n00b

Reputation: 23

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">
                    <thead>
                                   <tr>
                                                       <th>ID</th>
                                                       <th>Namn</th>
                                                       <th>Active</th>
                                   </tr>
                </thead>
                <tbody>
                                   <tr ng-repeat="item in dRows">
                                                       <td>{{item.ID}}</td>
                                                       <td>{{item.Name}}</td>
                                                       <td>{{(item.Active)}}</td>
                                   </tr>
                </tbody>

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

Upvotes: 0

Views: 84

Answers (1)

Marcus H&#246;glund
Marcus H&#246;glund

Reputation: 16811

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>

Upvotes: 1

Related Questions