Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display placeholders in AngularJS for undefined expression values?

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.

like image 556
JustGoscha Avatar asked Mar 27 '13 12:03

JustGoscha


People also ask

Why placeholder is not working in angular?

If your placeholder is not working then it simply means that you have assigned them some value to that input. In your case, I am 100% sure that {{ d. placeholder }} holds some value( might be value equal to ' '). Assign this value to NULL.

What is placeholder in angular?

Placeholders can be used to enhance the experience of your application. You will, need set some custom widths to toggle their visibility. Their appearance, color, and sizing can be easily customized with our utility classes.

What are placeholder values?

The Placeholder Value enables you to provide a hint text about the values that need to be entered in an input field. On the entry page, this text is visible inside the input area, and disappears once the user starts typing in the field.

What is placeholder code?

Placeholders in sample code and commands represent values that the user must replace when they use the sample input. Placeholders in example output can also represent other values that vary. In general, a placeholder has a descriptive name as a default value.


1 Answers

{{ 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> 
like image 197
Umur Kontacı Avatar answered Sep 22 '22 21:09

Umur Kontacı