产生该错误的原因是因为代码中出现了一些类型不匹配的问题,即你可能在给定类型中没有定义某个属性或方法。
解决这个问题的方法是,在对应的组件或服务中import相应的方法或属性,并确保将其正确引入。
例如,在下面的代码中,我们遇到了'Property 'pipe' does not exist on type”的错误:
import { Component } from '@angular/core'; import { Observable } from 'rxjs/Observable';
@Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent { title = 'My App';
message$: Observable
constructor() { this.message$ = this.getTitle().pipe(); }
getTitle(): Observable
在这个例子中,我们忘记了包含rxjs / operators的import语句,从而导致找不到pipe属性。要解决这个问题,我们只需要在文件中添加以下行:
import 'rxjs/add/operator/pipe';
这样,我们就可以在文件中使用pipe方法了。