ANGULAR: The type does not contain a property called 'pipe'

As a beginner in Angular, I am attempting to filter an array by using modulus on the id when clicking a button. Despite researching online and trying to use pipe for this purpose, I keep encountering an error stating that "pipe" does not exist. I am unsure why this is happening. Using .filter() on its own does not work, and incorporating pipe does not solve the issue either. Am I heading in the wrong direction for a simple onclick filter? Below is the code I am working with:

Here is the code snippet:

import { Component, OnInit} from '@angular/core';
import { StreamService } from '../stream.service';
import { Stream } from '../stream';
import { map } from 'rxjs/operators';


@Component({
  selector: 'app-discover',
  templateUrl: './discover.component.html',
  styleUrls: ['./discover.component.scss']
})
export class DiscoverComponent implements OnInit {
  streams!: Stream[];
  
  constructor(private streamService: StreamService) { 
    
  }

  ngOnInit() {
    this.getStreams();
  }

  getStreams(){
    this.streamService.getStream().subscribe((data =>{
      this.streams = data;
      console.log(this.streams);
    }))
  }


  filterIsUneven(){
  this.streams.pipe(map((streams => streams.filter(stream => stream.id % 3)))
  };

}
<div class="container">

  <div class="buttons">
    <button (click) = "filterIsUneven()"> Games </button>
    <button> Music </button>
    <button> Esports </button>
    <button> IRL </button>
    <button>Back</button>
  </div>

  <div class="streams" *ngFor="let stream of streams">
    <h3>{{stream.id}}</h3>
    <h3>{{stream.title}}</h3>
    <img src="{{stream.thumbnailUrl}}">
  </div>

</div>
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Stream } from './stream';
import { Observable} from 'rxjs';
 
@Injectable({
  providedIn: 'root'
})
export class StreamService{

constructor(private http: HttpClient) { }

getStream():Observable<Stream[]>{
  return this.http.get<Stream[]>("https://jsonplaceholder.typicode.com/albums/1/photos");
  }

getLiveStream(id:number):Observable<Stream[]> {
  const url = `https://jsonplaceholder.typicode.com/albums/1/photos?id=${id}`;
  return this.http.get<Stream[]>(url);
  }
}

Answer №1

By placing this.streams within get streams, the type of this.streams changes from an observable to Stream[]. Consequently, when filterIsUneven() is called, the pipe method cannot be utilized on streams as it is no longer an observable. The alternative approach is to implement the following logic:

filterIsUneven(){
  this.streams.filter(stream => stream.id % 3)
 };

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

Angular 2 template can randomly display elements by shuffling the object of objects

I am working with a collection of objects that have the following structure: https://i.stack.imgur.com/ej63v.png To display all images in my template, I am using Object.keys Within the component: this.objectKeys = Object.keys; In the template: <ul ...

Class that can be exported with a nested object stored as a property

I am working on developing a reusable class with an object as a property in Angular 2. My goal is to allow binding my form to it using NgModel. For instance, let's say I have the following object: user: { name: string, address: { street: str ...

Can you explain the concept of BuildOptions in Sequelize?

Despite poring through the sequelize documentation and conducting extensive searches online, I have yet to come across a satisfactory answer: Why is BuildOptions necessary and what impact does it have on the created model? import { Sequelize, Model, Data ...

Exploring the HttpClient inheritance feature in Angular 6

I have customized the httpClient in an Angular project to include a special parameter in the options. This modification is working perfectly in my application. Here is the structure of my new service: export class CustomHttpClient extends HttpClient ...

My ng new project is experiencing some issues as it seems to be stuck at "CREATE project/src/app/app.component.css (0 bytes)". Can someone help

As of yesterday, my angular projects were running smoothly. However, starting today, I am facing a persistent issue where the project gets stuck without any error messages. Here is a snapshot of my terminal when the project gets stuck: C:&b ...

Differences in file sizes in Angular-CLI builds

After building my Angular app, I noticed the following output: https://i.sstatic.net/ZRtxU.png Upon closer inspection, it is evident that 0.7f787ebcd865a23bb4ea.chunk.js and vendor.fbdfd024192bddab02d3.bundle.js are quite large. To confirm their sizes, ...

The name property of event.currentTarget is now being returned as currentTarget

I am facing an issue with my handleChange function in typescript. When I try to retrieve the name attribute from a text field and log it, it returns 'currentTarget' instead of the assigned name. Additionally, the value is showing up as undefined. ...

Issues with the Angular Global Messaging service and how to tackle them

I am currently developing a web application using Angular 7 and I have implemented an API interceptor to show alerts when errors occur. Everything was working fine until I added a messaging service and messaging component. When I tried pushing the error me ...

What is the process for removing items from Firebase Storage utilizing Angularfire2?

Hello, I am new to using Angularfire2 and I am facing an issue with deleting a folder from Firebase Storage when a user presses the delete button. I have searched through the Angularfire2 documentation but couldn't find any information on how to achie ...

What is the best way to refresh data in ngrx/store after a "hard navigation"?

Within my application, I fetch all data in the "Items-Overview-Component" during initialization. The router path for this component is "/items". // Items-Overview-Component constructor(private store: Store<fromReducer.State>) { this.store.dispat ...

Unable to display surface chart using Plotly in Angular 12

I've been attempting to display a 3D model using Plotly (https://github.com/plotly/angular-plotly.js/blob/master/README.md), but unfortunately, the chart is not appearing. component.component.ts import { Component } from '@angular/core'; @ ...

Using React to Filter cards according to the selected value from an Autocomplete feature

I'm currently developing a React application that utilizes Material-UI's Autocomplete component to filter cards based on selected car brands. These cards represent various models, and the goal is to update them when a user picks a brand from the ...

What methods can be used to test scss subclasses within an Angular environment?

Exploring different background colors in various environments is a task I want to undertake. The environments include bmw, audi, and vw, with each environment having its own unique background color. Need help writing an Angular test for this? How can I mod ...

The Angular ngFor directive seems to be failing to display the items within the array, even though accessing the items directly by using array[index

I've come across a strange issue with a simple program I'm working on. I want to display a list of numbers using an array, but when I try to use *ngFor in Angular, the elements don't render. However, if I manually reference each element in t ...

Utilizing string to access property

Is there a better way to access interface/class properties using strings? Consider the following interface: interface Type { nestedProperty: { a: number b: number } } I want to set nested properties using array iteration: let myType: Type = ...

Can anyone offer any suggestions for this issue with Angular? I've tried following a Mosh tutorial but it's

Just finished watching a video at around 1 hour and 35 minutes mark where they added the courses part. However, I encountered an error during compilation. ../src/app/app.component.html:2:1 - error NG8001: 'courses' is not recognized as an elemen ...

When Using TypeScript with Serverless, 'this' Becomes Undefined When Private Methods are Called from Public Methods

Currently, I am working on constructing an AWS Serverless function using TypeScript. My focus is on creating an abstract class with a single public method that invokes some private methods. Below is the simplified version of my TypeScript class: export ...

Deactivate Search Functionality for Users who are not Logged in on an Angular 2 Application

The login component and view are functioning as intended, preventing users from accessing AuthGuard protected routes if they're not logged in. However, I'm facing a challenge with the search bar displayed on the home login screen (actually presen ...

Solving the loop in Angular: Strategies for resolving dependencies between directives and components

There is a RadioButtonComponent and a RadioButtonGroupDirective that have a dependency on each other: RadioButtonComponent: import { RadioButtonGroupDirective } from "./radio-button-group.directive"; ... constructor(@Optional() @Inject(forwardRef(() =&g ...

Guide to implementing lazy loading and sorting in p-Table with Angular2

I recently implemented lazy loading in my application and now I am having trouble with sorting items. When lazy loading is disabled, the sorting feature works perfectly fine. However, I need help to make both lazy loading and sorting work simultaneously. C ...