Join the Stack Overflow Community
Stack Overflow is a community of 6.8 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I need one help.I need to check if the array has no value and display one message there using Angular.js.I am explaining my code below.

  <table class="table table-bordered table-striped table-hover" id="dataTable">

<thead>
<tr>
<th>Sl. No</th>

<th>Date</th>
<th>
Info(Academic Year,Section,Subject,Semester)
</th>
<th>
Unit Name
</th>
<th>
Lecture Plan
 </th>
<th>Action</th>
</tr>
</thead>
<div ng-if="viewIncompletePlanData.length>0">
<tbody id="detailsstockid">
<tr ng-repeat="p in viewIncompletePlanData">
<td>{{$index+1}}</td>

<td>{{p.date}}</td>
<td>{{p.session}},{{p.section_name}},{{p.subject_name}},{{p.semester}}</td>
<td>{{p.unit_name}}</td>
<td>{{p.plan}}</td>
<td> 
<a >
<input type='button' class='btn btn-xs btn-success' value='Update' ng-click="">  
</a>
</td>
</tr>   
</tbody>
</div>
<div ng-if="viewIncompletePlanData.length==0">
<tr>
<center><p><b>No Record Matched</b></p></center>
</tr>
 </div>
</table>

In the above code i need when viewIncompletePlanData has no value it will display message there No record found Otherwise display the array result.Please help me.

share|improve this question
    
Try this: <td ng-show='viewIncompletePlanData.length===0'>No record found</td> – Rayon Nov 30 '15 at 8:50
    
if >0 no record found ? – subhra Nov 30 '15 at 8:51
up vote 0 down vote accepted

You can check the length of the array. If the length > 0 then show the records in table else if array is undefined or length === 0 then show No Record Found in the first row of table.

    <table>
        <tbody id="detailsstockid">
            <tr ng-repeat="p in viewIncompletePlanData" ng-if="viewIncompletePlanData.length>0">
                <td>{{$index+1}}</td>
                <td>{{p.date}}</td>
                <td>{{p.session}},{{p.section_name}},{{p.subject_name}},{{p.semester}}</td>
                <td>{{p.unit_name}}</td>
                <td>{{p.plan}}</td>
                <td>
                   <a>
                     <input type='button' class='btn btn-xs btn-success' value='Update' ng-click="">  
                   </a>

                </td>
            </tr>
            <tr ng-if="viewIncompletePlanData== null || viewIncompletePlanData.length === 0">
                <td>
                    No Record Found
                </td>
            </tr>
        </tbody>
    </table>
share|improve this answer

You can do it by ng-if / ng-show / ng-hide

Try like this

<table class="table table-bordered table-striped table-hover" id="dataTable">
   <thead>
      <tr>
         <th>Sl. No</th>
         <th>Date</th>
         <th>Info(Academic Year,Section,Subject,Semester)</th>
         <th>Unit Name</th>
         <th>Lecture Plan</th>
         <th>Action</th>
      </tr>
   </thead>
   <tbody id="detailsstockid">
      <tr ng-repeat="p in viewIncompletePlanData" ng-if="viewIncompletePlanData.length>0">
         <td>{{$index+1}}</td>
         <td>{{p.date}}</td>
         <td>{{p.session}},{{p.section_name}},{{p.subject_name}},{{p.semester}}</td>
         <td>{{p.unit_name}}</td>
         <td>{{p.plan}}</td>
         <td>
            <a>
            <input type='button' class='btn btn-xs btn-success' value='Update' ng-click="">  
            </a>
         </td>
      </tr>
      <tr ng-if="viewIncompletePlanData.length==0">
         <td colspan="6">
            <center>
               <p><b>No Record Matched</b>
               </p>
            </center>
         </td>
      </tr>
   </tbody>
</table>
share|improve this answer
    
Yes,its coming but message is coming avobe the table. – subhra Nov 30 '15 at 9:01
    
you wanna to show it inside table ? @subhra – Anik Islam Abhi Nov 30 '15 at 9:03
    
yes,check my updated post again. – subhra Nov 30 '15 at 9:04
    
@subhra your placement is wrong – Anik Islam Abhi Nov 30 '15 at 9:06
    
Can you make this correct ? – subhra Nov 30 '15 at 9:07

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.