Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display "-" if value is empty?

Tags:

angularjs

Is there any way to say in angular something like this :

<th ng-repeat=" o in Odds" >{{o.Name || "-"}}</th>

So if there is no data in o.Name to display "-" ?

like image 652
None Avatar asked May 22 '15 14:05

None


People also ask

How do you use an IF function for a blank cell?

Sometimes you need to check if a cell is blank, generally because you might not want a formula to display a result without input. In this case we're using IF with the ISBLANK function: =IF(ISBLANK(D2),"Blank","Not Blank")

How do you make Excel formula show blank if no data?

Under Display options for this worksheet, select a worksheet, and then do one of the following: To display zero (0) values in cells, select the Show a zero in cells that have zero value check box. To display zero values as blank cells, clear the Show a zero in cells that have zero value check box.

How do I show blank cell instead of #value?

To display errors as blank cells, delete any characters in the box. Change empty cell display Select the For empty cells show check box. In the box, type the value that you want to display in empty cells. To display blank cells, delete any characters in the box.

How do you know if a cell is empty in Excel?

If a cell is blank, the result is a status of "Open". The logical expression ="" means "is empty". In the example shown, column D contains a date if a task has been completed.

How to check if value is empty in JavaScript?

Check if value is empty in JavaScript Javascript Web Development Object Oriented Programming Use the condition with “” and NULL to check if value is empty. Throw a message whenever ua ser does not fill the text box value.

How to evaluate blank or not blank cells using if statement?

If a cell is blank, then it returns TRUE, else returns FALSE. Following examples will explain the difference to evaluate Blank or Not Blank cells using IF statement. To evaluate the cells as Blank, you need to use either logical expression Equal to Blank (=””) of ISBLANK function inthe logical_test argument of the IF formula.

How to check if the text box value is empty?

Use the condition with “” and NULL to check if value is empty. Throw a message whenever ua ser does not fill the text box value.


1 Answers

Your example should work, but if you have whitespace or a function in o.Name it will not resolve to falsey and you will get an invisible space in the HTML rather than the desired dash.

A generic filter could be used to substitute empty values for dashes and apply various normalisation on the input first:

angular.module('App.filters', []).filter('placeholder', [function () {
    return function (text, placeholder) {
        // If we're dealing with a function, get the value
        if (angular.isFunction(text)) text = text();
        // Trim any whitespace and show placeholder if no content
        return text.trim() || placeholder;
    };
}]);

You can then use it as follows:

<th ng-repeat=" o in Odds" >{{o.Name | placeholder:'-'}}</th>

This is then completely reusable for other rows/columns and anywhere else you want to apply the same rule.

Example: http://jsfiddle.net/kfknbsp7/4/

like image 91
seanhodges Avatar answered Oct 20 '22 12:10

seanhodges