How to display placeholders in AngularJS for undefined expression values?

后端 未结 5 1692
情歌与酒
情歌与酒 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:59

    Implementing default-ish filters works, but if you're using only numbers you can use angular's own number filter

    If the input is null or undefined, it will just be returned. If the input is infinite (Infinity or -Infinity), the Infinity symbol '∞' or '-∞' is returned, respectively. If the input is not a number an empty string is returned.

    {{ (val | number ) || "Number not provided"}}
    

提交回复
热议问题