admin管理员组

文章数量:1327924

I have table that is populating a list using angularjs controller. How can I show a place holder(say a dash sign) if the place expression is null or undefined??

Here is a snippet.

I am populating the view as:

<td>{{trans.Status}}</td>
<td>{{trans.PaymentId}}</td>
<td>{{trans.TransId}}</td>

I found about ng-show in angular docs. But I really don't want to use an extra span under td as this

<span class="empty" ng-show="!trans.TransId">N/A</span>

Is there any better way to do this.

I have table that is populating a list using angularjs controller. How can I show a place holder(say a dash sign) if the place expression is null or undefined??

Here is a snippet.

I am populating the view as:

<td>{{trans.Status}}</td>
<td>{{trans.PaymentId}}</td>
<td>{{trans.TransId}}</td>

I found about ng-show in angular docs. But I really don't want to use an extra span under td as this

<span class="empty" ng-show="!trans.TransId">N/A</span>

Is there any better way to do this.

Share Improve this question asked Aug 7, 2015 at 16:23 Language LassiLanguage Lassi 2,63022 silver badges25 bronze badges 5
  • 1 possible duplicate of Angular Template Default Value if Binding Null / Undefined (With Filter) – Tom Pietrosanti Commented Aug 7, 2015 at 16:26
  • 1 I think your question is answered here: stackoverflow./questions/16523076/… – Tom Pietrosanti Commented Aug 7, 2015 at 16:26
  • Might it be a good idea to give your fields a default value? Or is that impossible dud to further design of the Javascript? – Xyv Commented Aug 7, 2015 at 16:27
  • <td>{{trans.TransId || 'N/A'}}</td> – James Brierley Commented Aug 7, 2015 at 16:27
  • Thanks @TomPietrosanti those answers what I were looking for. – Language Lassi Commented Aug 7, 2015 at 16:38
Add a ment  | 

1 Answer 1

Reset to default 8

You can do the following:

<td>{{trans.Status}}</td>
<td>{{trans.PaymentId}}</td>
<td>{{trans.TransId || 'N\A'}}</td>

本文标签: javascriptShow a placeholder if value is null in html table using angularjsStack Overflow