Using a pipe to display the length of an array in Angular 4 using *ng

I'm struggling with displaying a "No Records Found" message in my app that features a range slider. Whenever the range slider is dragged, the results are updated based on the value of "sliderPipe". Despite this, I am unable to show the message when no records are found.

HTML Template

<div class="well" *ngFor="let data of onewayFormData$ | 
                                  sliderPipe: sliderValue as results;">
  <div class="row">
    <div class="col-md-6 onewayresults">
      <h2> {{ data.cost | currency: 'INR':true }} </h2>
      <h3> {{ data.agencycode }} </h3>
      <h5> {{ data.ocity }} > {{ data.dcity }}</h5>
      <h5> Depart: {{ data.depart }} </h5>
      <h5> Arrive: {{ data.arrive }} </h5>
    </div>
    <div class="col-md-6">
      <div style="float:right;">
        <img [src]="data.imageurl" width="120px" height="100px" [alt]="data.agency" />
        <br/>
        <br/>
        <button class="btn btn-success"> Book Tickets </button>
      </div>
    </div>
  </div>
  Length: {{ results }}
  <div class="well" *ngIf="results.length == ''">
    <div class="alert alert-danger"> No Results Found....... </div>
  </div>
</div>

Pipe Code

import { Pipe, PipeTransform } from '@angular/core';

@Pipe({
  name: 'sliderPipe'
})
export class SliderPipePipe implements PipeTransform {
  transform(value, args ? ) { // ES6 array destructuring
  console.log('Arguments: ' , value.length);
  return value.filter(data => {
      return data.cost >= args;
    });
  }
}

Answer №1

If data is a list:

A list will always have a length that is a numerical value, so ensure to compare against data.length == 0 to determine if the list is empty.

If data is a numeric value:

Simply verify with data == 0.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is it necessary to conceal Angular navigation controls when the user is not authenticated?

In Angular, is there a standardized method for hiding controls when the user is not logged in? We already have the CanActivate guard which checks if a user can access a route. Would it be better to hide the route initially if the user is not logged in or l ...

Exploring how to utilize checkboxes in Angular Material for data filtering from a database. Encountering an issue with the error message "nameValue

When attempting to utilize checkboxes to filter data in a material table, I ensured there were no errors present on my terminal or console. However, upon checking a checkbox in the browser, an error message stating "nameValue.toLowerCase is not a function" ...

Mastering checkbox selection in Angular reactive formsLearn how to effortlessly manage the checked status of

I am struggling with setting the checked status of a checkbox control within an Angular reactive form. My goal is to change the value based on the checked status, but it seems like the value is controlling the status instead. For instance, I want the for ...

What is the process for connecting a form to a model in Angular 6 using reactive forms?

In the time before angular 6, my approach involved utilizing [(ngModel)] to establish a direct binding between my form field and the model. However, this method is now considered deprecated (unusable with reactive forms) and I find myself at a loss on how ...

I am interested in monitoring for any alterations to the @input Object

I've been attempting to detect any changes on the 'draft' Object within the parent component, however ngOnChange() does not seem to be triggering. I have included my code below, but it doesn't even reach the debugger: @Input() draft: ...

File upload not functioning correctly with Angular 7 MEAN stack when using multer middleware

I am currently using the multer middleware for file upload in my Angular mean stack project. However, I am facing an issue where I am unable to retrieve req.file but can successfully access req.body, indicating that the file is not being uploaded. When I c ...

Angular's Async Pipe displaying outdated data

I am encountering an issue with my Angular async pipe setup. Here is the code snippet: <ng-container *ngIf="showProjects && (projects | async) as projectList; else loading"> In my projects.page.ts file, I have the following funct ...

Can a TypeScript interface inherit from multiple other interfaces simultaneously?

Hello Angular Community, I have a question regarding nesting three interfaces within another interface. Let me explain with some code: I am attempting to integrate the IProject1, IProject2, and IProject3 interfaces into the IAdmin2 interface: Thank you ...

Using FormControl Inheritance in Angular 4

My goal is to enhance the functionality of a FormControl by creating a subclass with additional properties. These properties will then be utilized in custom form controls to modify behavior. I attempted to inherit from FormControl (let's call it Stan ...

What causes a hyperlink to take longer to load when using href instead of routerLink in Angular 2+?

As I work on my web application using angular 2 and incorporating routes, I noticed a significant difference in loading speed based on how I link to another component. Initially, being new to angular, I used the href attribute like this: <a href="local ...

Troubleshooting an issue with asynchronous reactive form validators in Angular

I encountered an issue where I need to access a service that sends an http request to an API to verify the existence of a given username. Snippet from Auth component: usernameCheck(username: string){ return this.http.get(this.baseUrl + "usernamecheck?u ...

Can you tell me about the interface type format used in the angular cli?

I found myself feeling disoriented while reading the documentation. ng generate interface <name> <type> There was ambiguity on what to input for the type field. Is it supposed to be a string, object, array, or can I define properties like ema ...

Guide on maintaining Spring Security authentication across Angular front-end

Following the initial feedback on my query, I made adjustments to my Spring Security setup and successfully logged in and accessed a test endpoint using Postman. However, when the same endpoint is called by Angular post successful login, the request fails, ...

Angular 4 encounters a hiccup when a mistake in the XHR request brings a halt to a

In my Angular 4 application, I have implemented an observable that monitors an input field. When it detects a URL being entered, it triggers a service to make an XHR request. Observable.fromEvent(this._elementRef.nativeElement, 'input') .debou ...

Encountering an error while trying to run NPM install

I have attempted to uninstall and reinstall angular cli by using the following commands: sudo npm uninstall -g @angular/cli sudo npm install -g @angular/cli However, every time I run npm install, I encounter the following error: npm ERR! Unexpected toke ...

Creating an Interactive Menu System with Nested Options in Angular 2

I have a JSON structure that I need to transform into a menu with sub-menus based on the value of the sub-menu_location field. Here's an example: { "data": [ { "menu_name": "Primary Operations", "enabled": true, "sub-menu_lo ...

Today is a day for coming together, not for waiting long periods of

When grouping by month and dealing with different days, I encountered an issue similar to the one shown in this image. https://i.stack.imgur.com/HwwC5.png This is a snapshot of my demo code available on stackblitz app.component.html <div *ngFor="let ...

Error encountered while attempting to globally install TypeScript using npm: "npm ERR! code -13"

Issue with npm error 13 Having trouble installing typescript-g package Error details: - errno: -13, - npm ERR! code: 'EACCES', - npm ERR! syscall: 'symlink', - npm ERR! path: '../lib/node_modules/typescript/bin/tsc', ...

Angular failing to recognize the && operator

I have a button that opens a dialog with the blockui feature. I am trying to close the dialog and set the blockui boolean variable to false in order to stop blocking the UI. However, in my HTML code (click)="blockedDialog=false && displayAddDialog=false", ...

With *ngFor in Angular, radio buttons are designed so that only one can be selected

My goal is to create a questionnaire form with various questions and multiple choice options using radio buttons. All the questions and options are stored in a json file. To display these questions and options, I am utilizing nested ngFor loops to differ ...