简体   繁体   English

Angular:您在需要流的地方提供了一个无效的对象。 你可以提供一个 Observable、Promise、Array 或 Iterable

[英]Angular: You provided an invalid object where a stream was expected. You can provide an Observable, Promise, Array, or Iterable

I'm following the tutorial of the Material autocomplete (with filter) component with my own array of values, but I hit the following error.我正在使用我自己的值数组来学习材料自动完成(带过滤器)组件的教程,但我遇到了以下错误。

core.js:1624 ERROR TypeError: You provided an invalid object where a stream was expected. You can provide an Observable, Promise, Array, or Iterable.
    at 

My TS:我的TS:

games: string[] = ['Title 1', 'Title 2', 'Title 3', 'RPG 1', 'FPS 1', 'MMO'];

  searchTerm = new FormControl();
  filteredGames: Observable<string[]>;

  constructor(private store: Store<fromRoot.State>) { }

  ngOnInit() {
    this.filteredGames = this.searchTerm.valueChanges
      .pipe(
        startWith(''),
        map(value => this._filter(value))
      );
  }

  private _filter(value: string): string[] {
    const filterValue = value.toLowerCase();

    return this.games.filter(option => option.toLowerCase().includes(filterValue));
  }

My HTML:我的 HTML:

<section class="search" fxLayoutAlign="center center" fxLayout="column">
  <form (ngSubmit)="onSubmit()">
      <mat-form-field class="example-full-width">
        <input type="text" placeholder="Pick one" aria-label="Number" matInput [formControl]="searchTerm" [matAutocomplete]="auto">
        <mat-autocomplete #auto="matAutocomplete">
          <mat-option *ngFor="let option of filteredGames | async" [value]="option">
            {{option}}
          </mat-option>
        </mat-autocomplete>
      </mat-form-field>
    </form>
</section>

I've looked around, but no luck.我环顾四周,但没有运气。 I'm confused since I'm using an Observable.我很困惑,因为我使用的是 Observable。 I'm working on Angular 6.我正在研究 Angular 6。

I've also tried to copy the whole example.. but I'm getting the same error there.我也试过复制整个例子..但我在那里遇到了同样的错误。

Had the same error, copy pasted example as well.有同样的错误,也复制粘贴的例子。 My problem was a wrong import.我的问题是导入错误。 Had:有:

import {startWith} from "rxjs/internal/operators/startWith";

instead of:代替:

import {startWith} from "rxjs/operators";

I hope it helps someone else.我希望它可以帮助别人。

You have <form> twice.你有两次<form> If you merge the two, it works ok.如果将两者合并,则可以正常工作。

<form (ngSubmit)="onSubmit()">
  <form class="example-form">
  ...
</form>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 类型错误:您提供了一个预期流的无效对象。 你可以提供一个 Observable、Promise、Array 或 Iterable - TypeError: You provided an invalid object where a stream was expected. You can provide an Observable, Promise, Array, or Iterable xplat您提供了一个无效的对象,该对象应在其中流。 您可以提供一个Observable,Promise,Array或Iterable - xplat You provided an invalid object where a stream was expected. You can provide an Observable, Promise, Array, or Iterable Angular 11 错误:您提供了无效的 object,而应为 stream。 您可以提供一个 Observable、Promise、Array 或 Iterable - Angular 11 error: You provided an invalid object where a stream was expected. You can provide an Observable, Promise, Array, or Iterable 您提供了“未定义”的预期流。 您可以提供一个Observable,Promise,Array或Iterable - You provided 'undefined' where a stream was expected. You can provide an Observable, Promise, Array, or Iterable 类型错误:您在需要流的地方提供了“未定义”。 你可以提供一个 Observable、Promise、Array 或 Iterable - TypeError: You provided 'undefined' where a stream was expected. You can provide an Observable, Promise, Array, or Iterable 错误类型错误:您在需要流的地方提供了“空”。 你可以提供一个 Observable、Promise、Array 或 Iterable - ERROR TypeError: You provided 'null' where a stream was expected. You can provide an Observable, Promise, Array, or Iterable TypeError:您在需要 stream 的地方提供了“未定义”。 部署angular时可以提供Observable、Promise、Array或Iterable - TypeError: You provided 'undefined' where a stream was expected. You can provide an Observable, Promise, Array, or Iterable when deploying angular Angular5:TypeError:您提供了&#39;undefined&#39;,其中包含一个流。 您可以提供Observable,Promise,Array或Iterable - Angular5 : TypeError: You provided 'undefined' where a stream was expected. You can provide an Observable, Promise, Array, or Iterable 错误类型错误:您在需要流的地方提供了“未定义”。 您可以在 Angular 服务中提供 Observable、Promise、Array 或 Iterable - ERROR TypeError: You provided 'undefined' where a stream was expected. You can provide an Observable, Promise, Array, or Iterable in Angular Services Angular 7 rxjs/forkJoin :您在需要流的地方提供了“未定义”。 你可以提供一个 Observable、Promise、Array 或 Iterable - Angular 7 rxjs/forkJoin : You provided 'undefined' where a stream was expected. You can provide an Observable, Promise, Array, or Iterable
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM