examples example else ejemplos javascript angularjs angularjs-filter angular-ng-if

javascript - example - ¿Cómo usar el filtro en ng-if y variable?



ngif else angular 6 (3)

En este ejemplo, uso el filtro en la ng-repeat , pero ¿cómo lo uso en una variable y ng-if , algo como:

{{languages.length | filter: {available: true}}}

y

ng-if="languages.length == 0 | filter: {available: true}"

Ver Fiddle .

HTML

<div ng-controller="mainController"> <div>There are {{languages.length}} languages in total.</div> <div>??? There are {{languages.length}} languages available.</div> <div ng-if="languages.length == 0">??? Sorry, there are no languages available.</div> <ol> <li ng-repeat="language in languages | filter: {available: true}">{{language.name}}</li> </ol> </div>

AngularJS

$scope.languages = [ {id:1, name:"German", available: false}, {id:2, name:"English", available: true}, {id:3, name:"French", available: false}, {id:4, name:"Italian", available: true}, {id:5, name:"Spanish", available: false} ];


¿Puedes probar esto?

<div ng-controller="mainController"> <div>There are {{languages.length}} languages in total.</div> <div>There are {{(languages|filter:{available:true}).length}} languages available.</div> <div ng-if="(languages|filter:{available:true}).length == 0">Sorry, there are no languages available.</div> <ol> <li ng-repeat="language in languages | filter: {available: true}">{{language.name}}</li> </ol> </div>


Solo para actualizar la respuesta anterior, no es necesario filtrar tres veces, cree una nueva variable ''filtrada'' en el primer filtro:

<div ng-controller="mainController"> <div>There are {{languages.length}} languages in total.</div> <div>There are {{(filtered = (languages|filter:{available:true})).length}} languages available.</div> <div ng-if="filtered.length == 0">Sorry, there are no languages available.</div> <ol> <li ng-repeat="language in filtered">{{language.name}}</li> </ol> filtered=[{{filtered}}] </div>

http://jsfiddle.net/to7z06ma/18/


<div ng-if="(answerText|lowercase)==''true''">T</div>

<div ng-if="(answerText|lowercase)==''false''">F</div>

Esto funciona para mi