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
Implement default
filter:
app.filter('default', function(){
return function(value, def) {
return (value === undefined || value === null? def : value);
};
});
And use it as:
{{ x | default: '?' }}
The advantage of the filter solution over {{ x || '?'}}
is that you can distinguish between undefined
, null
or 0
.