角度:錯誤 RangeError:超出最大調用堆棧大小 (ANGULAR: ERROR RangeError: Maximum call stack size exceeded)


問題描述

角度:錯誤 RangeError:超出最大調用堆棧大小 (ANGULAR: ERROR RangeError: Maximum call stack size exceeded)

我正在嘗試通過單擊多個按鈕在 id 上使用 modula 來過濾我的數組。我嘗試使用管道,但建議我使用它,因為使用管道對我不起作用。我不知道該怎麼做,我在網上看到很多視頻,但它們太複雜了,或者我總是遇到一些他們沒有的錯誤。或者我只是在一個簡單的點擊過濾器中走錯了方向。我是角度 錯誤

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);
    }))
  }

  sortBack(){
    this.streams.sort((a, b) => a.id ‑ b.id);
  }


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



}
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);
  }
}
<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>

參考解法

方法 1:

console.log() in filterIsUneven is causing endless recursion. Remove console log and it should be fine.

(by swordsantomek550)

參考文件

  1. ANGULAR: ERROR RangeError: Maximum call stack size exceeded (CC BY‑SA 2.5/3.0/4.0)

#filtering #TypeScript #Angular #arrays






相關問題

禁止查找和 grep“無法打開”輸出 (Suppress find & grep "cannot open" output)

directx10 中的精靈和紋理過濾 (Sprites in directx10 and texture filtering)

使用 Lucene 統計分類結果 (Using Lucene to count results in categories)

根據 URL 變量過濾 HTML 內容 (Filtering HTML content based on URL Variable)

網格列包含 int64 值,但過濾器顯示字符串並且不起作用/ (Grid column contains int64 values but filter shows strings and doesn't work/)

angularjs中的雙重過濾 (dual filtering in angularjs)

按序列順序過濾 Birt 表 (Filter in serial order for Birt tables)

日期的 Drupal 8 上下文過濾器 (Drupal 8 contextual filter for date)

在VB中過濾一個wpf collectionviewsource? (Filter a wpf collectionviewsource in VB?)

遍歷對象並返回匹配的鍵/值 (Traverse object and return matching key / values)

過濾Python列表時出現意外輸出:我做錯了什麼? (Unexpected output when filtering Python list: What am I doing wrong?)

角度:錯誤 RangeError:超出最大調用堆棧大小 (ANGULAR: ERROR RangeError: Maximum call stack size exceeded)







留言討論