Filtering a multi-dimensional array in Ionic 3

I attempted to filter an array from a JSON with the following structure

{ID: "2031", title: "title 1", image: "http://wwwsite.com/im.jpg", url: 
       "url...", Goal: "3000000", …}

The array is named 'loadedprojects' and below is the filtering function:

getItems(ev: any) {
    // Reset items back to all of the items
      this.getloadedproject();

    // set val to the value of the searchbar
    let val = ev.target.value;

    // if the value is an empty string don't filter the items
    if (val && val.trim() != '') {
      this.loadedprojects = this.loadedprojects.filter((project) => {
        console.log( this.loadedprojects);
        return (project.title.indexOf(val) > -1);
      })
    }
  }

On the HTML page:

<ion-searchbar  (ionInput)="getItems($event)"></ion-searchbar>

Preview of the HTML page:

<ion-card *ngFor="let project of loadedprojects">
      <img  src="{{project.image}}" />
      <ion-card-content>
        <ion-card-title>{{ project.title }}</ion-card-title>
        <p>{{ project.country }}</p>
      </ion-card-content>

      <ion-grid >
        <ion-row>
          <ion-col col-6> {{ 'Goal' | translate }}</ion-col>
          <ion-col col-6 class="value-amount"> {{ project.Goal | number }} رق </ion-col>
        </ion-row>

        <ion-row>
          <ion-col col-6> {{ 'Donations' | translate }}</ion-col>
          <ion-col col-6 class="value-amount"> {{ project.Donation | number }} رق </ion-col>
        </ion-row>
        <ion-row>
          <ion-col col-6> {{ 'Donors' | translate }}</ion-col>
          <ion-col col-6 class="value-amount"> {{ project.nbr_donors }} </ion-col>
        </ion-row>
        <ion-row>
          <ion-col col-12>
            <button ion-button block class="donate_button" (click)="donation_options(project.ID, project.title, project.image)">{{ 'Donate' | translate }}</button>
          </ion-col>
        </ion-row>
      </ion-grid>



    </ion-card>

I am facing issues with the search system implementation.

Answer №1

Avoid using [(ngModel)]="keyword". Instead, consider the alternative approach presented below.

<ion-searchbar (ionInput)="updateList($event)"></ion-searchbar>

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

Ways to rejuvenate an angular component

I am in the process of developing a mobile application using ionic 4. The app supports two languages, namely ar and en. The menu drawer is a pre-built component included within the app. In order to ensure that the drawer component displays the correct sty ...

Exploring angular2 nested routes and their construction using routerLink

I have been working on implementing a nested nested route structure where I have tabs within tabs using dynamic loading with the Angular 2 material tab component. The first nested tab works as expected, however, I am facing issues with the second nested t ...

Angular's innerHTML dilemma

Within my Angular service, I have implemented three methods as shown below: public loadLiveChat() { let url: string; url = this.appConfig.config.liveAgent.liveAgentScriptUrl; this.dynamicallyLoadScript(url); ...

Change icons in Ionic 5 when selecting a tab

How can I change my tab icons to outline when not selected and filled when selected? The Ionic 5 Tabs documentation mentions a getSelected() method, but lacks examples on its usage. I plan to utilize the ionTabsDidChange event to detect tab clicks, then ...

Assign the private members of the class to the arguments of the constructor

class Bar { #one #two #three #four #five #six #seven #eight #nine #ten #eleven #twelve #thirteen #fourteen #fifteen #sixteen constructor( one, two, three, four, five, six, seven, eight, ...

Hosted-Git-Info Regular Expression Denial of Service attack

I am facing a vulnerability in my Ionic/Angular app. The issue suggests updating the version of hosted-git-info. However, I cannot find this package in my package.json file. Can you provide guidance on how to resolve this? https://www.npmjs.com/advisorie ...

Implement FieldResolver in TypeGraphQL for an array of objects

My current dilemma revolves around a specific issue related to the definition of my Cart type, which is structured as follows: @ObjectType() export class Cart { @Field(() => ID) id: string; @Field((_type) => String) ownerId: String ...

When using `JSON.stringify`, the resulting data may vary from the original object

Here is the code snippet in question: console.log("444444: ", profile, JSON.stringify(profile)) Upon checking the log output: https://i.stack.imgur.com/LzalV.png I am trying to understand why I cannot see the value: [0] present Additionally, ...

What is the best way to monitor parameter changes in a nested route?

I need assistance with managing routes const routes: Routes = [ { path: 'home', component: HomeComponent }, { path: 'explore', component: ExploreComponent, children: [ { path: '', component: ProductListC ...

Converting <reference path/> directive to ESM import: A step-by-step guide

As I embark on developing a TypeScript application, I've reached the realization that I am not a fan of using the <reference path /> triple-slash directive. Instead, I prefer utilizing import 'something'. However, every time I attempt ...

Transmit a form containing a downloaded file through an HTTP request

I am facing an issue with sending an email form and an input file to my server. Despite no errors in the console, I can't seem to upload the file correctly as an attachment in the email. post(f: NgForm) { const email = f.value; const headers = ...

Encountering an error stating "Argument of type 'X' is not assignable to parameter of type 'X' in the NextApiResponse within NextJS."

Here is the code snippet I am working with: type Data = { id: string; name: string; description: string; price: number; }; const FetchMeals = async (req: NextApiRequest, res: NextApiResponse<Data>) => { const response = await fetch( ...

Encoding and Decoding Base64 in Nativescript Using Angular 2

I've searched high and low for a solution but I can't seem to find one. Even after attempting to utilize atob() and btoa(), my efforts were futile. It seems that despite what intellisense suggests, these methods cannot be used. Additionally, plug ...

The dropdown for selecting months and years is not appearing on Angular 13's ngbdatepicker

Currently, I am developing a project in Angular 13 with Bootstrap 4. I am trying to implement a datePicker using ngbDatepicker, but unfortunately, the datePicker is not displaying the dropdowns for selecting months and years at the top. Here is the code sn ...

Utilize Bootstrap in an Angular template to effortlessly expand one element while collapsing all others

I'm facing an issue with a table in my component. Each row has a button that, when clicked, should expand to show some calculated data specific to that row. However, the problem is that when one button is expanded, it keeps other buttons expanded as w ...

Encountering a 500 error code while attempting to send a post request using Angular

Whenever I attempt to send a post request to Django server, I encounter a 500 (Internal Server Error) response. Interestingly, the get and put requests work flawlessly on the same server where Django is connected to PostgreSQL database. Here is a snippet ...

Encountering an error stating "unable to access properties of undefined (reading 'redirectUri')"

I am currently working on fetching details from Okta and saving them in a Store. My code includes an @effect that triggers a service file named a-service.ts. Inside the service constructor, I call the Okta library as shown below: @Injectable() export clas ...

Finding the perfect pairing: How to align counters with objects?

public counter = 0; x0: any; x1: any; x2: any; x3: any; x4: any; next(){ this.counter += 1; this.storage.set("Count", this.counter); console.log(this.counter); this.logic(); } logic(){ //automatic counter here var xNum = JSON.parse(JSON.stri ...

When posting on social platforms, the URL fails to display any metadata

We recently completed a project (Web Application) using React .net core with client-side rendering in React. One challenge we encountered was that when the app loads in the browser, it only displays the static HTML initially without the dynamic meta tags. ...

Typescript is throwing an error when trying to use MUI-base componentType props within a custom component that is nested within another component

I need help customizing the InputUnstyled component from MUI-base. Everything works fine during runtime, but I am encountering a Typescript error when trying to access the maxLength attribute within componentProps for my custom input created with InputUnst ...