亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

錯誤:InvalidPipeArgument:管道“AsyncPipe”

錯誤:InvalidPipeArgument:管道“AsyncPipe”

哈士奇WWW 2023-10-04 14:36:55
我發現了幾個具有相同標題的問題,據我所知,其中一些問題表明解決方案基本上是返回一個 Observable 而不是一個數組(其他問題是關于 FireBase 的,這不是我的情況)。好吧,就我而言,下面的代碼確實返回一個 Observable (查看“getServerSentEvent(): Observable {return Observable.create ...”)我的最終目標是獲取從 Rest WebFlux 返回的流中的所有事件。我沒有通過后端,因為我很確定這個問題與 Angular 中的一些錯誤有關。最重要的是,我可以調試并查看事件是否正確地從 app.component.ts 傳送到 extratos$(參見下圖)。整條日志core.js:6185 ERROR Error: InvalidPipeArgument: '[object Object]' for pipe 'AsyncPipe'    at invalidPipeArgumentError (common.js:5743)    at AsyncPipe._selectStrategy (common.js:5920)    at AsyncPipe._subscribe (common.js:5901)    at AsyncPipe.transform (common.js:5879)    at Module.??pipeBind1 (core.js:36653)    at AppComponent_Template (app.component.html:8)    at executeTemplate (core.js:11949)    at refreshView (core.js:11796)    at refreshComponent (core.js:13229)    at refreshChildComponents (core.js:11527)應用程序組件.tsimport { Component, OnInit } from '@angular/core';import { AppService } from './app.service';import { SseService } from './sse.service';import { Extrato } from './extrato';import { Observable } from 'rxjs';@Component({  selector: 'app-root',  templateUrl: './app.component.html',  providers: [SseService],  styleUrls: ['./app.component.css']})export class AppComponent implements OnInit {  //extratos: any;  extratos$ : Observable<any>;  constructor(private appService: AppService, private sseService: SseService) { }  ngOnInit() {    this.getExtratoStream();  }  getExtratoStream(): void {    this.sseService      .getServerSentEvent("http://localhost:8080/extrato")      .subscribe(        data => {          this.extratos$ = data;        }      );  }}
查看完整描述

1 回答

?
斯蒂芬大帝

TA貢獻1827條經驗 獲得超8個贊

當您編寫此內容時observer.next(this.extratos);,這意味著您在回調的參數this.extratos中在組件端得到的內容,因此當您這樣做時,您實際上是在存儲. TypeScript 不會抱怨這一點,可能是因為當您像您一樣從頭開始構建時,它不夠智能來推斷類型。datathis.extratos$ = data;extratos ArrayObservable

嘗試這個:

this.extratos$ = this.sseService
      .getServerSentEvent("http://localhost:8080/extrato");

并在模板中:<div *ngFor="let ext of extratos$ | async">


查看完整回答
反對 回復 2023-10-04
  • 1 回答
  • 0 關注
  • 112 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號