4
Using Angular, in my controller I have a function that calculates the amount of filtered items.
Thus:
$scope.totalConferenciasRestantes = function () {
return $scope.solicitacoes.data.filter(function (solicitacao) {
return solicitacao.conferido == 0;
}).length;
};
In my view, I need to display the value of this function over and over again. But I have to call the function several times is a bad practice, since you can store the value once in a variable and reuse it if necessary.
Example:
var x = y();
inserir(x);
alert('o valor de x é ' + x);
In the case of Angular, you can do this in the view?
Example:
<div ng-if='totalConferenciasRestantes() > 0'>
Falta conferir {{ totalConferenciasRestantes() }}!
</div>
In the above case, it would be like calling in the view totalConferencaisRestantes
only once?
Good... you can even do
contagem_de_items = (items | filter: {marcado: false}).length
– Wallace Maxters