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

标签 angular typescript

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

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/

相关文章:

angular - 在 Angular 项目中放置类型/类的位置

angular - 如果 CORS header ‘Access-Control-Allow-Origin’ 是 ‘*’,则不支持凭据

angular - 测试 FormArray

javascript - Cordova 应用程序从头开始,关于 ngCordova、Ionic 和 Typescript 的决定

angular - Material Angular Accordion 标题/标题高度

angular - 垫表根据条件显示行

angular - setInterval vs Observable的timer方法,哪个更适合创建timer

javascript - 使用 TypeScript 和 Promises 异步加载/卸载内容

javascript - 即使不在 console.log 中,值也为 null (...)

angular - 在 Angular 中,*ngFor ="let item from list | async"是什么意思?