Failed to apply currency mask on an if inline

Asked

Viewed 25 times

0

I have a condition where I need to apply the monetary mask.

<td>
    <div class="pull-left">{{nota.issRetido[0] === true ? nota.qtdNotasEmitidas | currency : '-'}}</div>
    <div class="pull-right">{{nota.issRetido[0] === false ? nota.qtdNotasEmitidas| currency  : '-'}}</div>
</td>

When passing the '| currency :' for condition when it is true, returns siyntax Syntax Error

However, this error only occurs in the condition of this if inline. How do I put the mask in this situation?

  • If I didn’t, it is pq returns me an error. And n has why put a code I know where the error is. And currency, as described, was trying to apply it within: {{note.issRetido[0] === false ? note.qtdNotasEmitidas | currency : '-'}}

  • So in order to help, we need to test the code, to know what’s in nota.qtdNotasEmitidas .. etc. If you do not want to add the code, create a [mcve]. Check the version you are using from Angularjs.

  • Try to do with if else normal applying the currency

  • As it would be, this if Else normal?

1 answer

0

Hello, in the code you are adding the mask to the currency but not inserting the condition else, then to ask any questions goes an example using parentheses () to limit the condition:

angular.module('myApp', [])
.controller('myCtrl', function($scope) {
  $scope.nota = {};
  $scope.nota.issRetido = [];
  $scope.nota.issRetido[0] = true;
  $scope.nota.qtdNotasEmitidas = 1;
  });
<html lang="pt-br">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular.min.js"></script>
<body>

<div ng-app="myApp" ng-controller="myCtrl">

<h3>Limitando com parênteses e adicionando máscara "currency : '-'"</h3>
<div class="pull-left">{{nota.issRetido[0] === true ? (nota.qtdNotasEmitidas | currency : '-') : '' }}</div>
<div class="pull-right">{{nota.issRetido[0] === false ? (nota.qtdNotasEmitidas | currency:'-') : '' }}</div>

<h3>limitando com parênteses e sem máscara</h3>
<div class="pull-left">{{nota.issRetido[0] === true ? (nota.qtdNotasEmitidas | currency) : '-' }}</div>
<div class="pull-right">{{nota.issRetido[0] === false ? (nota.qtdNotasEmitidas | currency) : '-' }}</div>

</div>
</body>
</html>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.