Replacing null data with null in angular js

I need to display a table in an html page using ng-repeat. most records in the table have null data, but I cannot replace null with empty or string zero. I tried {{row || 'null'}}, but that didn't help. When it generates a table, it is completely disabled if the rows have a large number of zeros.

     <table>
        <tr>
            <th ng-repeat="colname in sqldata.collist">{{colname}}</th>
        </tr>
        <tr ng-repeat="rows in sqldata.tablist">
            <td ng-repeat="row in rows">{{ row || 'null' }}</td>
        </tr>
    </table>

enter image description here

+4
source share
3 answers

What about the old ng-show and ng-hide trick to show something if the value is null.

Replace

{{ row || 'null' }}

from

<div ng-show="row">{{row}}/div>
<div ng-hide="row">null</div>
+4
source

. , DOM . .

, " " , .

<div ng-app="test" ng-controller="ClientCtrl">
    <div ng-repeat="elem in elems">
        {{elem | isempty}}
    </div>
</div>

JavaScript

angular.module('test', []).filter('isempty', function() {
    return function(input) {
        return isEmpty(input) ? 'No Value' : input;
    };

    function isEmpty (i){
        return (i === null || i === undefined);
    }
})

http://jsfiddle.net/5hqp5wxc/

: https://docs.angularjs.org/guide/filter

+1
Another option is ng-if
 <table>
        <tr>
            <th ng-repeat="colname in sqldata.collist">{{colname}}</th>
        </tr>
        <tr ng-repeat="rows in sqldata.tablist">
            <td ng-repeat="row in rows">
              <span ng-if="row" >{{ row }} </span>
              <span ng-if="!row" > null </span>
            </td>
        </tr>
    </table>
0
source

Source: https://habr.com/ru/post/1606311/


All Articles