2014-09-25 34 views
0

在下面的代码片段中,status返回0或1,但是我希望每当status返回0和“Old”时评估和显示单词“New” “每当log.status返回时1.我如何评估和更改客户端的值?如何在html文件中评估和更改AngularJS表达式的值

 <table class="table table-striped table-hover table-bordered table-condensed"> 
     <thead> 
      <tr> 
       <th>Date</th> 
       <th>Status</th> 
     </thead> 
     <tr class="info" ng-repeat="log in vm.data> 
      <td>{{log.Date | date}}</td> 
      <td>{{log.Status}}</td> 
     </tr> 
    </table> 

回答

2

的开箱即用的解决方案是

{{ log.Status == 0 ? 'New' : 'Old'}} 

另一种方法是创建一个小的过滤器。

.filter('condition', function() { 
    return function(input, trueValue, falseValue) { 
     return input ? trueValue : falseValue; 
    }; 
}) 

然后在你的代码

{{ log.Status | condition: 'Old' : 'New' }}