Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
170
rated 0 times [  177] [ 7]  / answers: 1 / hits: 45224  / 11 Years ago, wed, march 27, 2013, 12:00:00

If I have an expression {{ x }} and x is undefined or null, then how can I display a placeholder for it?



I provided one solution in my answer, but I would like to know what other ways there are.
Maybe, also for placeholder for promises.


More From » angularjs

 Answers
51

{{ counter || '?'}}.
Just pure javascript. || can be used as default value. Since it would be different empty messages in each, a generalized directive would not be suitable for many cases.



If you want to apply a different class to empty ones, that's also built-in:



<div ng-class={empty: !counter} ng-bind=counter || ?></div>

[#79311] Tuesday, March 26, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kristopherw

Total Points: 173
Total Questions: 107
Total Answers: 98

Location: Lesotho
Member since Wed, Jun 2, 2021
3 Years ago
;