在AngularJS中切换货币格式

时间:2015-06-16 12:44:39

标签: angularjs angularjs-filter

基本上我试图做的是允许用户选择是否显示美元格式。很简单,只需使用ng-class来切换课程,对吧?除了现在在空单元格中,一个美元符号显示出来。

如果我们使用自定义过滤器呢?好吧,我真的不知道如何打开或关闭自定义过滤器。

任何建议都会有所帮助。

这是切换格式的按钮(它运行一个将格式设置为true或false的函数)。

<button class="btn format-toggle" ng-click="setFormat();">Show <span ng-show="format">Hours</span><span ng-hide="format">Dollars</span></button>

我试图影响的代码

<table>
  <tr ng-repeat="project in projects">
    <td>{{project.name}}</td>
    <td ng-repeat="month in project.months" ng-class="{dollar : format}">{{month.total}}</td>
  </tr>
</table>

1 个答案:

答案 0 :(得分:0)

我实际上回答了我自己的问题,但我想如果其他人觉得它有用,我会把它留下来。

我最后只使用ng-class和其他条件来检查单元格中是否有值。

<td ng-repeat="month in project.months" ng-class="{dollar : format && month !== undefined}">{{month.total}}</td>

CSS:

.dollar:before{
  content:'$';
}
相关问题