# How to check the result value in template?

**URL:** <https://forum.ionicframework.com/t/how-to-check-the-result-value-in-template/120215>\
**Category:** ionic-v3\
**Created:** [February 2, 2018, 5:08am UTC](https://forum.ionicframework.com/t/how-to-check-the-result-value-in-template/120215 "2018-02-02T05:08:48Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![anespa](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/anespa/32/116051_2.png) [@anespa](https://forum.ionicframework.com/u/anespa)\
**Post date:** [February 2, 2018, 5:08am UTC](https://forum.ionicframework.com/t/how-to-check-the-result-value-in-template/120215/1 "2018-02-02T05:08:48Z")

</div>

Friends,

I try to show “No search result” when result is null using

```auto
<div *ngIf="result?.value == null">
          <h2>Search results</h2>
        No search results , please try
      </div>

```

But it’s not work…

in my controller when the Search return no result shows : ‘null’ value as alert.  
My need is before submitting form no need to show “No Search results, please try” message but after search and no result show same…

Please advise . I am using ionic 3…

Anes

---

<div class="post-metadata">

**Author:** ![sujit77](https://avatars.discourse-cdn.com/v4/letter/s/6bbea6/32.png) [@sujit77](https://forum.ionicframework.com/u/sujit77)\
**Post date:** [February 2, 2018, 5:33am UTC](https://forum.ionicframework.com/t/how-to-check-the-result-value-in-template/120215/2 "2018-02-02T05:33:08Z")

</div>

I can’t understand your conditional logic.  
Can you try checking [documentation for ternary operation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_Operator)

---

<div class="post-metadata">

**Author:** ![AaronSterling](https://avatars.discourse-cdn.com/v4/letter/a/51bf81/32.png) [@AaronSterling](https://forum.ionicframework.com/u/AaronSterling)\
**Post date:** [February 2, 2018, 5:38am UTC](https://forum.ionicframework.com/t/how-to-check-the-result-value-in-template/120215/3 "2018-02-02T05:38:05Z")

</div>

It is bad style to do this in the template. In general, keep your template clean and free of logic, so if you have a bug, you know exactly where in your file structure to look. Better to do`*ngIf="searchResultsExist"` where `searchResultsExist` is a boolean.

---

<div class="post-metadata">

**Author:** ![anespa](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/anespa/32/116051_2.png) [@anespa](https://forum.ionicframework.com/u/anespa)\
**Post date:** [February 2, 2018, 5:47am UTC](https://forum.ionicframework.com/t/how-to-check-the-result-value-in-template/120215/4 "2018-02-02T05:47:27Z")

</div>

Hi Aaron,

problem in your logic is that without searching the form shows the default “No Search data found” message

```auto
<div *ngIf="!status">
            <h2>Search results</h2>
          No search results , please try
        </div>

```

in controller

```auto
status: boolean;
this.result = data;
 if(this.result!=null) { this.status = true;}

```

In default situation it’s value is false , so when form loads show that message … please  
advise

---

<div class="post-metadata">

**Author:** ![AaronSterling](https://avatars.discourse-cdn.com/v4/letter/a/51bf81/32.png) [@AaronSterling](https://forum.ionicframework.com/u/AaronSterling)\
**Post date:** [February 2, 2018, 5:51am UTC](https://forum.ionicframework.com/t/how-to-check-the-result-value-in-template/120215/5 "2018-02-02T05:51:13Z")

</div>

> [@anespa](#):
>
> problem in your logic

That’s one possible explanation! Do please read the link @sujit77 gave you.

---

<div class="post-metadata">

**Author:** ![anespa](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/anespa/32/116051_2.png) [@anespa](https://forum.ionicframework.com/u/anespa)\
**Post date:** [February 2, 2018, 5:52am UTC](https://forum.ionicframework.com/t/how-to-check-the-result-value-in-template/120215/6 "2018-02-02T05:52:50Z")

</div>

i feel it’s not useful in my case … i tried it no success…

---

<div class="post-metadata">

**Author:** ![sujit77](https://avatars.discourse-cdn.com/v4/letter/s/6bbea6/32.png) [@sujit77](https://forum.ionicframework.com/u/sujit77)\
**Post date:** [February 2, 2018, 5:56am UTC](https://forum.ionicframework.com/t/how-to-check-the-result-value-in-template/120215/7 "2018-02-02T05:56:50Z")

</div>

I am guessing that `result` is your variable depending on which you want to show/hide `No search result` statement. Right?

If so, try this -

```auto
*ngIf="result == null || result == '' ? true : false"

```

---

<div class="post-metadata">

**Author:** ![reedrichards](https://avatars.discourse-cdn.com/v4/letter/r/34f0e0/32.png) [@reedrichards](https://forum.ionicframework.com/u/reedrichards)\
**Post date:** [February 2, 2018, 6:00am UTC](https://forum.ionicframework.com/t/how-to-check-the-result-value-in-template/120215/8 "2018-02-02T06:00:42Z")

</div>

```
<div *ngIf="result != null && result.value == null">
      <h2>Search results</h2>
    No search results , please try
  </div>

```

but agree with @AaronSterling

---

<div class="post-metadata">

**Author:** ![anespa](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/anespa/32/116051_2.png) [@anespa](https://forum.ionicframework.com/u/anespa)\
**Post date:** [February 2, 2018, 6:03am UTC](https://forum.ionicframework.com/t/how-to-check-the-result-value-in-template/120215/9 "2018-02-02T06:03:55Z")

</div>

> [@reedrichards](#):
>
> \*ngIf=“result != null && result.value == null”

It’s not working …

---

<div class="post-metadata">

**Author:** ![anespa](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/anespa/32/116051_2.png) [@anespa](https://forum.ionicframework.com/u/anespa)\
**Post date:** [February 2, 2018, 6:06am UTC](https://forum.ionicframework.com/t/how-to-check-the-result-value-in-template/120215/10 "2018-02-02T06:06:16Z")

</div>

> [@sujit77](#):
>
> \*ngIf=“result == null || result == ‘’ ? true : false”

Not working on loading itself show “No Search results, please try”

---

<div class="post-metadata">

**Author:** ![sujit77](https://avatars.discourse-cdn.com/v4/letter/s/6bbea6/32.png) [@sujit77](https://forum.ionicframework.com/u/sujit77)\
**Post date:** [February 2, 2018, 6:09am UTC](https://forum.ionicframework.com/t/how-to-check-the-result-value-in-template/120215/11 "2018-02-02T06:09:15Z")

</div>

It is because initially your `result` variable has not data.  
Try assigning some value into it like `true`.

Then above condition will fail and user won’t see `No result find`.  
Later after AJAX call you can change its value depending upon returned datas.

---

<div class="post-metadata">

**Author:** ![reedrichards](https://avatars.discourse-cdn.com/v4/letter/r/34f0e0/32.png) [@reedrichards](https://forum.ionicframework.com/u/reedrichards)\
**Post date:** [February 2, 2018, 6:18am UTC](https://forum.ionicframework.com/t/how-to-check-the-result-value-in-template/120215/12 "2018-02-02T06:18:52Z")

</div>

> [@anespa](#):
>
> It’s not working …

```
<div *ngIf="result != null && (!result.value || result.value.length === 0)">
  <h2>Search results</h2>
  No search results , please try
</div>

```

---

<div class="post-metadata">

**Author:** ![anespa](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/anespa/32/116051_2.png) [@anespa](https://forum.ionicframework.com/u/anespa)\
**Post date:** [February 2, 2018, 6:19am UTC](https://forum.ionicframework.com/t/how-to-check-the-result-value-in-template/120215/13 "2018-02-02T06:19:23Z")

</div>

But in my case

```auto
<h2 *ngIf="result?.length > 0">Search results</h2>

```

works fine … But this checking lost ☹

---

<div class="post-metadata">

**Author:** ![sujit77](https://avatars.discourse-cdn.com/v4/letter/s/6bbea6/32.png) [@sujit77](https://forum.ionicframework.com/u/sujit77)\
**Post date:** [February 2, 2018, 6:22am UTC](https://forum.ionicframework.com/t/how-to-check-the-result-value-in-template/120215/14 "2018-02-02T06:22:29Z")

</div>

I am not sure regarding the logic you are using.  
Is that `result` variable an array?

If so, try this for showing “No results” sentence -

```auto
*ngIf="result.length == 0"

```

---

<div class="post-metadata">

**Author:** ![anespa](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/anespa/32/116051_2.png) [@anespa](https://forum.ionicframework.com/u/anespa)\
**Post date:** [February 2, 2018, 6:28am UTC](https://forum.ionicframework.com/t/how-to-check-the-result-value-in-template/120215/15 "2018-02-02T06:28:50Z")

</div>

> [@sujit77](#):
>
> esult.length == 0

it will cause Run time error as

> Error: Template parse errors:  
> Parser Error: Conditional expression result?result.value requires all 3 expressions at the end of the expression [value is:{{result?result.value}}hi] in ng:///AppMod

---

<div class="post-metadata">

**Author:** ![sujit77](https://avatars.discourse-cdn.com/v4/letter/s/6bbea6/32.png) [@sujit77](https://forum.ionicframework.com/u/sujit77)\
**Post date:** [February 2, 2018, 6:34am UTC](https://forum.ionicframework.com/t/how-to-check-the-result-value-in-template/120215/16 "2018-02-02T06:34:50Z")

</div>

Then use -

```auto
*ngIf="!result.length"

```

Try debugging it from your side too.  
Also it will be more helpful if you mention some JavaScript codes as well.

---

<div class="post-metadata">

**Author:** ![anespa](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/anespa/32/116051_2.png) [@anespa](https://forum.ionicframework.com/u/anespa)\
**Post date:** [February 2, 2018, 8:39am UTC](https://forum.ionicframework.com/t/how-to-check-the-result-value-in-template/120215/17 "2018-02-02T08:39:01Z")

</div>

Friends,

at last worked with

```auto
<div *ngIf="searchFlag && result?.length==null">
                <h2>Search results</h2>
              No search results , please try
        </div>

```

Thanks

Anes

---

<div class="post-metadata">

**Author:** ![mhartington](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mhartington/32/137757_2.png) [@mhartington](https://forum.ionicframework.com/u/mhartington)\
**Post date:** [July 19, 2021, 9:52pm UTC](https://forum.ionicframework.com/t/how-to-check-the-result-value-in-template/120215/18 "2021-07-19T21:52:30Z")

</div>

Closed on July 19, 2021, 9:52pm UTC


