Angular 2 default value in view

做~自己de王妃 提交于 2021-02-10 22:38:12

问题


I would like to give a default value of a variable in my view if it's empty or not defined :

<p>{{(person | async)?.name}}</p>

If the field name is empty, i would like to see this :

<p>Default value</p>

How can i do this ?


回答1:


use ||operator

<p>{{(person | async)?.name || 'Default value'}}</p>


来源:https://stackoverflow.com/questions/51139331/angular-2-default-value-in-view

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!