Learner Learner - 1 year ago 73
AngularJS Question

default text when the input is empty in angular for label while binding

I have this piece of code that is working fine and displays the data as per received from controller into the binding. However, I tried to make server data as string.empty and I was expecting this default text "Your name" would appear, and it is not. I want the default text to be shown if server returns empty string.

<label for="name" class="label-proj" ng-bind="ctrl.name">Your name</label>

Answer Source

You could do the following:

<label for="name" class="label-proj">{{ctrl.name || "Your name"}}</label>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download