gpt4 book ai didi

angular - 错误 : Property 'pipe' does not exist on type 'Observable'

转载 作者:太空狗 更新时间:2023-10-29 17:41:11 30 4
gpt4 key购买 nike

我从这里复制粘贴其中一个示例:

https://material.angular.io/components/autocomplete/overview

HTML:

<form class="example-form">
<mat-form-field class="example-full-width">
<input type="text" placeholder="Pick one" aria-label="Number" matInput [formControl]="myControl" [matAutocomplete]="auto">
<mat-autocomplete #auto="matAutocomplete">
<mat-option *ngFor="let option of filteredOptions | async" [value]="option">
{{ option }}
</mat-option>
</mat-autocomplete>
</mat-form-field>
</form>

TS:

import {Component} from '@angular/core';
import {FormControl} from '@angular/forms';
import {Observable} from 'rxjs/Observable';
import {startWith} from 'rxjs/operators/startWith';
import {map} from 'rxjs/operators/map';

/**
* @title Filter autocomplete
*/
@Component({
selector: 'autocomplete-filter-example',
templateUrl: 'autocomplete-filter-example.html',
styleUrls: ['autocomplete-filter-example.css']
})
export class AutocompleteFilterExample {

myControl: FormControl = new FormControl();

options = [
'One',
'Two',
'Three'
];

filteredOptions: Observable<string[]>;

ngOnInit() {
this.filteredOptions = this.myControl.valueChanges
.pipe(
startWith(''),
map(val => this.filter(val))
);
}

filter(val: string): string[] {
return this.options.filter(option =>
option.toLowerCase().indexOf(val.toLowerCase()) === 0);
}

}

CSS:

.example-form {
min-width: 150px;
max-width: 500px;
width: 100%;
}

.example-full-width {
width: 100%;
}

但是我得到这个错误:

Failed to compile: Property 'pipe' does not exist on type 'Observable'.

知道为什么吗?

最佳答案

Please check for the RxJS version compatibility.

As i did go through you code and found correct and working. Kindly see for the version of RxJS should be > 5.5

关于angular - 错误 : Property 'pipe' does not exist on type 'Observable<any>' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47699090/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com