如何显示AngularJS未定义前pression值的占位符? [英] How to display placeholders in AngularJS for undefined expression values?

查看:180
本文介绍了如何显示AngularJS未定义前pression值的占位符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个前pression {{X}} x是未定义,那我怎么才能显示它的占位符?

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.

推荐答案

{{计数器|| '?'}}
只是纯粹的JavaScript。 || 可作为默认值。因为它是在每一个不同的空消息,广义指令将不适合于许多情况

{{ 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>

这篇关于如何显示AngularJS未定义前pression值的占位符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆