Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 2 Markup - If String is Empty display something else

So in AngularJS there was a way, in the markup, to bind data to a string like this:

{{myString | 'N/A'}}

What this did was, in one quick swipe, display the string if it wasn't empty. If it was empty, it would display the text behind the pipe.

Now I'm using Angular 2 and I'm trying to do the same thing except I can't seem to find the syntax to do so. Has anyone tried doing this yet? If so, how can I go about it without having to do it in the component level.

Thanks

like image 813
LorenIpsum Avatar asked Oct 13 '16 19:10

LorenIpsum


1 Answers

Single pipe is Bitwise OR is consider as Pipe in Angular 2 which look up for filter with name after | symbol. You should be using || instead of |(single pipe).

{{myString || 'N/A'}}
like image 70
Pankaj Parkar Avatar answered Nov 15 '22 22:11

Pankaj Parkar