Angular:您提供了一个无效的对象,其中需要一个流。您可以提供一个可观察的、承诺的、数组的或可观察的
我正在学习使用我自己的值数组的材质自动完成过滤器组件的教程,但是我遇到了以下错误Angular:您提供了一个无效的对象,其中需要一个流。您可以提供一个可观察的、承诺的、数组的或可观察的,angular,angular-material,Angular,Angular Material,我正在学习使用我自己的值数组的材质自动完成过滤器组件的教程,但是我遇到了以下错误 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 我的TS: games: string[] = ['Title 1', 'Title 2', 'Ti
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
我的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));
}
我的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>
我环顾了四周,但运气不好。我很困惑,因为我使用的是可观察的。我正在研究Angular 6
我还试图复制整个示例。。但我在那里也遇到了同样的错误。你有两次。如果将两者合并,则效果良好
...
也有同样的错误,复制粘贴的示例。我的问题是输入错误。 曾: 而不是:
import {startWith} from "rxjs/operators";
我希望它能帮助其他人。我在发布问题时看到了这一点。。所以我把它修好了。但我还是收到了那个错误。我把你的代码复制到了一个StackBlitz中,删除第二个代码时效果很好,那么还发生了什么我的意思是,你的代码是非常可复制的。在我看来,可能是你商店里的某个东西抛出了错误。我从构造函数中取出了它,因为你发布的代码没有使用它。发生了什么?我不知道。。我从示例中复制了代码,并调整了数组,然后发现了错误。我要试试那家商店。谢谢
import {startWith} from "rxjs/operators";