How to display placeholders in AngularJS for undefined expression values?

后端 未结 5 1686
情歌与酒
情歌与酒 2021-02-02 05:13

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

5条回答
  •  独厮守ぢ
    2021-02-02 05: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:

提交回复
热议问题