Konrad the n00b Konrad the n00b - 1 year ago 80
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

Answer Source

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>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download