如果绑定角模板默认值空/未定义(带过滤器) [英] Angular Template Default Value if Binding Null / Undefined (With Filter)
本文介绍了如果绑定角模板默认值空/未定义(带过滤器)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个模板绑定,显示所谓的约会的模式属性,它是一个日期,采用了棱角分明的日期过滤器。
I have a template binding that displays a model attribute called 'date' which is a date, using Angular's date filter.
<span class="gallery-date">{{gallery.date | date:'mediumDate'}}</span>
到目前为止好。然而此刻,如果有在日期字段没有值,结合无显示。不过,我想它来显示字符串各种如果没有日期。
So far so good. However at the moment, if there is no value in the date field, the binding displays nothing. However, I would like it to display the string 'Various' if there is no date.
我可以使用二进制运营商处获得的基本逻辑:
I can get the basic logic using a binary operator:
<span class="gallery-date">{{gallery.date || 'Various'}}</span>
不过,我不能让它使用日期过滤器工作:
However I can't get it to work with the date filter:
<span class="gallery-date">{{gallery.date | date:'mediumDate' || "Various"}}</span>
如何使用二进制运算符旁边的日期过滤器?
推荐答案
打开了所有我需要做的是包裹前pression的左侧软括号:
Turns out all I needed to do was wrap the left-hand side of the expression in soft brackets:
<span class="gallery-date">{{(gallery.date | date:'mediumDate') || "Various"}}</span>
这篇关于如果绑定角模板默认值空/未定义(带过滤器)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文