Filter dynamic values in the mat-select dropdown using the mat-select-filter component

I'm having trouble using the mat-select-filter to filter data:

<mat-form-field *ngIf="fundComplexesList">
                        <mat-select placeholder="Using array of objects">
                              <mat-select-filter [placeholder]="'Filter'"     [displayMember]="'fundComplexName'" [array]="fundComplexesList" (filteredReturn)="filteredList5   =$event"></mat-select-filter>
                            <mat-option *ngFor="let item of filteredList5" [value]="item">
                                {{item.fundComplexName}}
                            </mat-option>
                        </mat-select>
                    </mat-form-field>

The value for fundComplexesList is fetched from an api call

    `ngOnInit(): void {
     this.agreementService.getFundComplexes(false).subscribe(data => {
     this.fundComplexesList = data;
    },
    error => {
    console.log('Error while binding FundComplex dropdown.');
    });
 `

Here's my filter method:

  `public filteredList5 =  this.fundComplexesList.slice();`

The issue arises when I try to use this.fundComplexesList value in public filteredList5 = this.fundComplexesList.slice(); function. Can anyone suggest a solution on how to ensure that the value in fundComplexesList is obtained before calling filteredList5 = this.fundComplexesList.slice();

Answer №1

HTML and TS Files for Angular Component

<mat-form-field *ngIf="fundComplexesList">
 <mat-select placeholder="Using array of objects">
   <mat-select-filter [placeholder]="'Filter'"  [displayMember]="'fundComplexName'" [array]="fundComplexesList" (filteredReturn)="filteredList5   =$event"></mat-select-filter>
     <mat-option *ngFor="let item of filteredList5" [value]="item">{{item.fundComplexName}}
     </mat-option>
    </mat-select>
  </mat-form-field>

Typescript Code in app.component.ts File

import { HttpClient } from '@angular/common/http';
import { Component } from '@angular/core';

@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css'],
})
export class AppComponent {
  fundComplexesList: any = [];

  public filteredList5: any;
  constructor(private http: HttpClient) {}
 ngOnInit(): void {
     this.agreementService.getFundComplexes(false).subscribe(data => {
      this.fundComplexesList = data;
      this.filteredList5 = this.fundComplexesList.slice();
},
error => {
    console.log('Error while binding FundComplex dropdown.');
   });
  }
}

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

Working with Angular 4 and Typescript: Transforming JSON data with json2typescript key mapping

Apologies for the confusion in my previous explanation. Let me clarify my question: In my Angular 4 application, I am using json2typescript to handle JSON to object conversion. However, I am facing an issue where the class structure I have defined does no ...

Encountering a 403 error when attempting to upload files to Google Cloud Storage (GCS) using Signed URLs

The main aim is to create a signed URL in the api/fileupload.js file for uploading the file to GCS. Then, retrieve the signed URL from the Nextjs server through the nextjs API at localhost://3000/api/fileupload. Finally, use the generated signed URL to upl ...

How to select a DOM element in Angular 2.x

Although it may seem simple, there are not many examples of using Angular 2.0 yet. In one of my components, I have a situation where I need to add a class to the body tag. However, my application is bootstrapped deeper than the body element, so I am looki ...

Ways to programmatically move from one step to another in ngx-admin nebular stepper

Currently utilizing the nebular ngx-admin template, I have encountered some challenges with the nebular stepper. Within one component, I have implemented four steps. In the component file, I have utilized Nebular API's methods: @ViewChild("stepp ...

Modify the data displayed on the chart by choosing the desired year from the dropdown options

In my Angular app, I am showcasing a chart that visualizes data based on selected starting and ending years from dropdown menus. The X axis represents 18 cities, while the Y axis displays "IAP" values. To calculate the "IAP" values for each city within the ...

Utilize Moment to retrieve the weekend dates

Currently tackling a date-related issue and feeling stuck. Is it feasible to extract weekends from an array of dates using Moment.js instead of the getDay() method? I'm a beginner in JavaScript. ...

FormArray vertical custom validationI hope this meets your requirements

I need the total to be exactly 100, but my Validator isn't functioning correctly. Can anyone spot what's wrong in my code? export class CustomValidators { public static verticalTotal(total: number, refControl: string) { return (control: Fo ...

Node Express and Typescript app are failing to execute new endpoints

Hello, I'm currently diving into Node express and working on a simple CRUD app for pets. So far, I've successfully created 2 endpoints that are functioning properly. However, whenever I try to add a new endpoint, Postman fails to recognize it, g ...

How to showcase unprocessed XML in an mdDialog

I am encountering an issue while trying to show XML content as is in an $mdDialog using Angular Material. When I use a standard alert, the XML appears correctly with all tags intact. However, when using $mdDialog or Angular, it seems to remove all the XML ...

Guide on validating and capturing business hours data from two separate fields into one input using Angular and Reactive Forms

https://i.sstatic.net/K5OA8.png My goal is to set up a reactive form using Angular, with the form group structure already defined in my .ts file as shown below: constructor( private fb:FormBuilder){} ngOnInit(): void { this.createBusinessListingF ...

Issue encountered when trying to redirect after user creation on the backend

To persist a user, I use this method inside form-registrar-usuario.component: registrarUsuario(){ const role = this.route.snapshot.params["role"] if(role == "Proponedor"){ this.autorizacionService.registrarUsuario( role, thi ...

Assigning variables in Angular ngFor loopFresh way to

Here is what I have: <div *ngFor="let item of order.items"> I want to show the result in this format: {{item.product.category.availability.selected.name.value}} {{item.product.category.availability.selected.id.value}} My goal is to assign all of ...

The distinction between <Type>function and function name():Type in TypeScript is essential to understand the various ways

function retrieveCounter(): Counter { let counter = <Counter>function (start: number) { }; counter.interval = 123; return counter; } Upon inspection of line 2 in the code snippet above, I am left wondering why I am unable to use function ...

Navigating through the exported components of a module without explicit type declarations

So I'm in the process of developing a module with sub-modules for Angular. Here's the notation I'm using: module App.services { export class SomeService { } } When initializing all services, I use the following code snippet: function ...

Exploring the ins and outs of data exchange within Angular 2

I'm currently in the process of developing an angular2 application. One of the components in my project is the MountainListComponent, which is composed of other components (although this detail is not crucial) and is nested within a parent component. ...

Exploring project references in TypeScript 3 with distinct `outDir` configurations

I am eager to utilize the project references functionality in TypeScript 3.1. Initially, my project's directory structure post-compilation appears as follows: . ├── A │ ├── a.ts │ ├── dist │ │ ├── A │ │ ...

ngx-datatable - Displaying No Results (Angular 6)

I'm currently working on populating a ngx-datatable using API response (async function). While I have successfully implemented the functions, I am facing an issue where the rows in the table appear blank, despite the correct number of rows being creat ...

What exactly is the purpose of the colon in JavaScript's import statement?

Looking at the following example. import { QueryClientContract, TransactionClientContract } from '@ioc:Adonis/Lucid/Database' I am puzzled by the use of colons and I am unsure about where the imported files are being referenced from. ...

Is there a way to selectively filter and display certain data in an Angular data table?

https://i.sstatic.net/0N3OZ.jpg I am currently working on a project using Angular 7 frameworks that involves dealing with large amounts of data. One of the tasks is to filter out trial units based on the 'userName' field in the raw data. I have ...

Encountering Undefined Object Error in Angular Framework

I just completed an upgrade to Angular and encountered an issue with the error message 'object is possibly undefined'. I have tried multiple solutions after doing some research online, including using 'if' statements, null coalescing, i ...