Filtering out HTTP JSON content using a pipe symbol

I'm encountering an issue while constructing a search field to filter the rows of my table. The problem lies in the fact that the "value" in my pipe is undefined.

Below is the code snippet:

Pipe:

@Pipe({
    name: 'filter',
    pure: false
})
export class SearchPipe implements PipeTransform {
    transform(value, searchinput) {
        if (!searchinput[0]) {
            return value;
        } else if (value) {
            return value.filter(item => {
                for (let key in item) {
                    if ((typeof item[key] === 'string' || item[key] instanceof String) &&
                        (item[key].indexof(searchinput[0]) !== -1)) {
                        return true;
                    }
                }
            });
        }
    }

Component:

  constructor(private _serverService: ServerService, private _router: Router) { }

    errorMessage: string;
    public servers: Server[];
    isLoading = true;

    selectedServer: Server;

    ngOnInit() {
          this.getServers('qa');
    }

    reloadServers(env) {
        this.servers = null;

        this.getServers(env);
    }

    getServers(env?) {
        this._serverService.getServers(env)
            .subscribe(
            value => {
                this.servers = value;
                this.isLoading = false;
            },
            error => this.errorMessage = <any>error);
    }

All data is correctly filled in my template, however the issue arises when attempting to perform a search. Upon debugging, I observed that the value parameter in my pipe is undefined.

Here is the template:

<input id="searchinput" class="form-control" type="text" placeholder="Search..."  [(ngModel)]="searchinput" />

<div id="searchlist" class="list-group">
    <table class="table table-bordered table-hover ">
         <thead>
            <tr>
                <th>Hostname</th>
            </tr>
         </thead>
         <tbody>
                <tr *ngFor="#server of servers | filter: searchinput">
                  <td>{{server.MachineNameAlias}}</td>
                </tr>
          </tbody>
     </table>
</div>

Furthermore, here is the error message:

EXCEPTION: TypeError: item[key].indexof is not a function in [servers | filter: searchinput in MainServerPage@35:40]

Answer №1

Make sure you're using the correct function name: it's indexOf, not indexof. This error could be why you're experiencing issues at the end.

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

"Extracting data from PHP arrays and converting it into

Here is the code snippet I am working with: Tipo_Id = mysql_real_escape_string($_REQUEST["tipo"]); $Sql = "SELECT DISTINCT(tabveiculos.Marca_Id), tabmarcas.Marca_Nome FROM tabmarcas, tabveiculos WHERE tabmarcas.Tip ...

Explore encoding of array objects into JSON format

I seem to be having trouble retrieving values from array objects. When passing my array of objects from PHP, I use the following syntax initiate_data(".json_encode($my_array)."); To check the array in JavaScript, I have written this code snippet functi ...

Retrieve the JSON file at regular intervals of n minutes

I've developed a code that retrieves a JSON file and processes it. However, the file is updated every 5 minutes. I need a solution that will allow my code to fetch the latest data without needing to refresh. This is how I currently fetch the JSON fil ...

The curious case of jQuery.parseJSON() failing to decode a seemingly valid Json string on a Windows-based server

I am currently running a WordPress JavaScript function code on a Linux server that also includes a PHP function called "get_form_data". jQuery.ajax({ type: "POST", url: MyAjax.ajaxurl, data: {action: "get_fo ...

Having trouble retrieving the value of a service within the @CanActivate decorator in the component

I am currently utilizing Angular 2.0.0-beta.15 and I am attempting to implement @CanActivate in the component. The code snippet below showcases my attempt: @CanActivate((next: ComponentInstruction, previous: ComponentInstruction) => { console.log(&ap ...

Utilizing Python to Retrieve JSON Information with Django

Whenever I try to extract data from JSON, I always encounter the error TypeError: unhashable type: 'dict' Here is my JSON information: u 'paging': { u 'cursors': { u 'after': u 'MTQyNzMzMjE3MDgxNzU ...

The Retrofit URL is dynamically updated when I pass in a query

Hey there, I'm new to using Retrofit and could use some help. I need the URL to look like this: When I set it up like this: @GET("paralleljson.php?action={terms}") Call<Terms_UserGuide_About> termsuserguide(@Path("terms") String terms,@Qu ...

Issue encountered with input form containing a JSON field in Rails version 4.2

Within my Rails 4.2 application utilizing a postgres database, the field ui_layout has been transformed into json within the database table (utilizing psql's support for the json data type). Previously, the ui_layout field was a text field. However, u ...

Is there a way to stop PrimeNG Tree onNodeSelect() event from triggering when utilizing templating?

How can I prevent a PrimeNG Tree with templating from selecting/deselecting the node on any click inside the template? Specifically, I want only a click on the <a> element to call doSomething(), not nodeSelected() as well. Here is the code snippet: ...

Excessive iterations occurring in JavaScript for loop while traversing an array

After addressing the issues raised in my previous inquiry, I have made significant progress on my project and it is now functioning almost exactly as intended. The main purpose of this website is to iterate through the World Of Tanks API to generate cards ...

How can one effectively manage multiple JSON Objects using Retrofit 2?

I am currently working on an Android project where I need to parse a JSON URL using Retrofit 2. The JSON data in the URL looks something like this: { "channel0":{ "song":"Crush", "artist":"Jennifer Paige", "duration":"180", "playedat":"1545065 ...

Transforming JSON with an array of CSV data into SQL

When retrieving data from an API, I receive the following JSON structure: {"Data":"header1,header2,header3,header4\\n9datacolumn1,datacolumn2,datacolumn3,datacolumn4\\n9datacolumn1,datacolumn2,datacolumn3,datacolumn4"} This JSON data ...

Subscribing to a GraphQL mutation through Angular with the Appsync client

Currently, I am developing a chat application in Angular using GraphQL with Appsync on AWS. The current process for creating a new chat involves mocking up the chat and sending it to the server. On the server-side, a unique chat_id is generated for each ch ...

Developing custom events in an NPM package

Developing a basic npm package with signalr integration has been my recent project. Here's how it works: First, the user installs the package Then, the package establishes a connection using signalr At a certain point, the server triggers a function ...

Mandatory classification eliminates understanding of function type

I'm currently trying to transform an optional argument from one type into a required one in my type definition. However, I am encountering some difficulties and can't seem to figure out what I'm doing wrong in the process. Would appreciate a ...

Angular CRUD Form Data Conversion Update

After selecting the date 3/2/2021 in my Angular create CRUD form, it gets passed to MongoDB as 2021-03-02T00:00:00.000+00:00 and then displayed on the update CRUD form as 2021-03-02T00:00:00.000Z. How can I convert this to 'M/d/yyyy' format? (I ...

Exploring the inner function within Angular using jasmine testing

While working on my project, I encountered a situation where I needed to define an inner function and assign it to a class variable for future use. The reason behind this decision was to have access to the parent function's arguments without granting ...

Tips for keeping your attention on the latest HTML element

Welcome to my HTML Template. <div cdkDropList class="document-columns__list list" (cdkDropListDropped)="dragDrop($event)" > <div cdkDrag class="list__box" ...

Displaying elements based on the selected mat-radio-button

I'm struggling with the logic to show and hide elements based on the selected radio button. Here's my current pseudocode: <mat-radio-button [value]="0">BUTTON A</mat-radio-button> <mat-radio-button [value]="1&quo ...

What is the functionality of the large arrow notation when used in conjunction with the value formatter in ag-Grid

In my Angular project, I have created a GridFormatterService service with static methods that can be used for value formatting in ag-Grid. For certain ag-Grids in the project, I need to pass a displayDateAndTime parameter (a boolean flag) from the column ...