0

I am getting some data from server and using ngFor to show them (It's search feature) but when there's no result, I want to show text saying 'There's no result"

How can I do this?

I tried this so far but this isn't working.

 <div *ngIf="teaInfo != '{}'">

        <div class="starter-template text-xs-center">
            <h5 style = "text-align:center">No result</h5>

        </div>

   </div>

2 Answers 2

2

Use ngSwitch to check data exist and show default message if no data available as below:

You can also get below result with help of IF statement but advisable to use Switch instead of If statement for better performance perspective.

<div [ngSwitch]="true">
    <div *ngSwitchCase="teaInfo != null && teaInfo.length>0">
        //Perform operation on data
    </div>
    <div *ngSwitchDefault>
         There's no result                 
     </div>
</div>
Sign up to request clarification or add additional context in comments.

Comments

0

NgFor is used for an array. So just check

*ngIf="teaInfo.length>0"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.