Exploring Angular RxJS: the art of filtering Observable arrays

Is there a way to effectively filter an array Observable in Angular? I am working with an observable Array:

announcementList$: Observable<Announcement[]> = this.announcementService.getAnnouncement(0,0).pipe(filter(Boolean),shareReplay(), map(({data}) => data));

Upon receiving a response from the server, the array looks like this:
        {
            "id": 109,
            "title": "Title 231231242342342342342342342",
            "body": "testing",
            "id_creator": 1,
            "creator_login": "landrynek",
            "created_at": "2020-04-08 13:58:45",
            "updated_at": "2020-04-08 14:48:24",
            "status": 1,
            "accepted_at": null,
            "deleted_at": null
        },
        {
            "id": 110,
            "title": "Title 231231242342342342342342342",
            "body": "testing",
            "id_creator": 1,
            "creator_login": "landrynek",
            "created_at": "2020-04-08 14:24:25",
            "updated_at": "2020-04-08 14:41:09",
            "status": 1,
            "accepted_at": null,
            "deleted_at": null
        },
        {
            "id": 112,
            "title": "Title 231231242342342342342342342dsaasassdadasda",
            "body": "testing sadasasa",
            "id_creator": 1,
            "creator_login": "landrynek",
            "created_at": "2020-04-08 14:24:34",
            "updated_at": "2020-04-08 14:48:55",
            "status": 1,
            "accepted_at": null,
            "deleted_at": null
        }

The filter array:

 filteredData$:Observable<any[]>;

My interface Announcement:

export interface Announcement{
    id: number;
    title: string;
    body: string;
    id_creator: number;
    creator_login: string;
    created_at: Date;
    updated_at: Date;
    status: number;
    acepted_at: Date;
    deleted_at:Date;
    price?: number;
    number_of_workers?: number;
    available?: Date;
    end_available?: Date;
}

Incorporating into HTML and my component.ts file:

<input type="text" (keyup)="updateFilter()" [formControl]="inputControl" required />

(component.ts)
inputControl = new FormControl();

Method used for filtering:

updateFilter() {
    this.filteredData$ = combineLatest(
      this.announcementList$,
      this.inputControl.valueChanges.pipe(
        startWith(""),
        debounceTime(400)
      )
    ).pipe(
      distinctUntilChanged(),
      filter(([list, input]) => Boolean(list)),
      map(([list, input]) => {
        return list.filter(
          ({ creator_login }) => creator_login === input);
      })
    );
    this.announcementList$ = this.filteredData$;

    this.table.offset = 0;
  }

When typing any string in the input field, the data is not being filtered.. How can I properly filter and display results in my HTML table? When I console.log the 'list' in the last filter, I see all data in the array but the input remains empty..

Answer №1

Implement the FormGroup, FormBuilder, and FormControl structure within a ReactiveForm for effective form handling.

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

Creating Personalized Validators for Angular Version 5 Reactive Forms

I am struggling to create a custom validator for my Angular v5 application. I followed the documentation for a basic password match example in the Docs, but it's not working as expected. this.personalInfoForm = _fb.group({ 'name': [null,V ...

How can you restrict the number of characters a user can input into an Angular input textbox?

I am using the textarea tag and I would like to limit the number of characters a user can type to 300. Currently, I have implemented real-time character count functionality, but I need to restrict input once it reaches 300 characters. Below is my HTML cod ...

Is it planned to include StencilJS as a development choice in Ionic?

I'm curious about the potential adoption of Stencil JS for developing mobile apps within the Ionic framework. When I mention "an option for developing," I'm referring to frameworks like NativeScript where developers can choose between Angular + ...

Improving event observation efficiency with Observable.fromEvent on the browser window

Within my file manager UI, each individual file item is currently set to monitor the window's wheel event. As soon as a file item comes into view on the page, its corresponding image loading process will be initiated by the file item component. While ...

Issue with the height not being updated in a parent React nested Accordion

Currently, I am in the process of developing the mobile version of my homepage. However, there seems to be a bug in my nested accordion labeled "Projects." The bug is causing an issue where the bottom projects section does not display at the correct height ...

Is it possible to replace checkboxes with dropdowns in the NG-ZORRO Tree component?

I am attempting to create a tree structure using the tree component from ng-zorro. However, instead of checkboxes for the leaf nodes, I would like to have dropdown menus. I tried using the ng-template but the checkbox is still appearing. Here is my code: ...

Angular's ng-for directive allows for easy iteration over a collection of

I have a list of links that I am looping through using the ng-for directive. Each link is supposed to display an icon with different timing intervals thanks to a plugin called wowjs. The first link should appear quickly, while the last one should appear sl ...

A solution to the error message "Type 'unknown' is not assignable to type 'Country[]' in React TypeScript" is to explicitly define the type of the

I encountered error TS2322: Type 'unknown' is not assignable to type 'Country[]' pages/Countries/index.tsx Full code: import * as ApiCountries from '../../services/APIs/countries.api' function Countries() { const findCo ...

Troubleshooting: Ngx-Echarts Animation Issue at Startup

I've been working on integrating ngx echarts into my Angular app, but I'm facing an issue with the animation during the initial load of the chart. Take a look at this Stackblitz example where you can see that the bars render quickly on initial lo ...

Guide on dividing a URL string in Angular framework

Is there a way to include a value directly in the URL, like so: http://example.com/component/july2021 I need to extract july2021 from the component and separate it into "july" and "2021". How can I achieve this? ...

Consolidation of files for Client-Code-Generation with Swagger-Codegen: What is the best way to merge all files into

Just recently started using Swagger and NodeJS, I successfully integrated Swagger into my NodeExpress application and generated typescript-client-code with Swagger-Codegen (specifically Typescript-Angular). However, the issue I am facing is that the gener ...

Resetting the input value for the typeahead component is currently not feasible

When using the typeahead component, it appears that clearing the input value after the results list is displayed is not possible. However, if the results list does not appear, the model can be cleared without any issues by using a button. Here are the ste ...

Updating a data attribute in Angular 2: A different approach

Currently, I am utilizing ConvertFlow to integrate pre-designed form templates into my project. To specify where the form should appear, I include a div with the unique identifier of the form created within their platform. While this process is straightfor ...

Tips for incorporating moment.js library into an Angular 2 TypeScript application

I attempted to utilize TypeScript bindings in my project: npm install moment --save typings install moment --ambient -- save test.ts file content: import {moment} from 'moment/moment'; I also tried without using TypeScript bindings: npm inst ...

The data type 'boolean' cannot be assigned to the type 'CaseReducer<ReportedCasesState, { payload: any; type: string; }>'

I recently developed a deletion reducer using reduxjs/toolkit: import { createSlice, PayloadAction } from "@reduxjs/toolkit"; import { AppThunk } from "../store"; import { ReportedCase, deleteReportCase } from "../../api/reportedCasesApi"; import history ...

Encountering a 404 XHR Error when attempting to add a component in Angular 4.1.0 within Plunker

Having some trouble setting up Angular 4 on Plunker and adding a new component. The following URL is where I'm working: https://plnkr.co/edit/1umcXTeug2o6eiZ89rLl?p=preview I've just created a new component named mycomponent.ts with the necessar ...

What is the best way to ensure that my variables are properly differentiated in order to prevent Angular --prod --aot from causing empty values at runtime?

While testing my code locally in production, the functions I've written are returning the expected values when two parameters are passed in. However, after running ng build --prod --aot, the variable name within the functions changes from name to t. ...

Unable to remove loading.tsx file

Currently tackling a project using Next.js, I decided to include loading.tsx within the app directory. However, upon attempting to delete it, an error crops up: Caused by: The system cannot find the file specified. (os error 2) The import trace for the r ...

Guide on inserting tooltip to designated header column in primeNG data table

Html <p-table #dt1 [columns]="cols" [value]="cars1"> <ng-template pTemplate="header" let-columns> <tr> <th *ngFor="let col of columns"> {{col.header}} </th> ...

Is it possible to integrate TypeScript 5.0 decorators into React components?

Every time I add decorators to my class, they always get called with the arguments specified for legacy decorators: a target, property key, and property descriptor. I am interested in using TypeScript 5.0 decorators. Is this feasible, and if so, how can I ...