Angular rxjs v6和rxjs/运算符出现错误

Angular rxjs v6和rxjs/运算符出现错误,angular,rxjs,Angular,Rxjs,我在实现rxjs v6和rxjs/运算符时遇到问题: import { Observable } from 'rxjs'; import { Subject } from 'rxjs'; import { startWith, debounceTime } from 'rxjs/operators'; export class ProductListComponent implements OnInit { public products$: Observable<Produc

我在实现rxjs v6和rxjs/运算符时遇到问题:

import { Observable } from 'rxjs';
import { Subject } from 'rxjs';
import { startWith, debounceTime } from 'rxjs/operators';

export class ProductListComponent implements OnInit {

    public products$: Observable<Product[]>;
    public searchTerm: string = '';

    private searchSubject: Subject<string> = new Subject();
    private reloadProductsList: Subject<void> = new Subject();

    constructor(private productService: ProductService) { }

    ng OnInit() {
        this.products$ = this.searchSubject
            .pipe(startWith(this.searchTerm), debounceTime(300));
    }
    ...
}

这个错误使我困惑。你能帮忙吗

是的,问题在于
startWith(this.searchTerm)
。您不能从它开始,因为它是一个字符串,
this.products$
是可观察的。另外,
this.searchSubject
Subject


您确定它不是
this.products$=this.productService.getProducts(),类似这样的?

嗯,这两个建议都不起作用。您愿意提供一个编码示例吗?好的,很好。我越来越近了。调用:this.products$=this.productService.getProducts(“”);结果:状态:404,状态文本:“未找到”,url:。那么,有没有一种方法可以查询localhost,看看它为什么找不到我的api调用?谢谢.constructor(私有http:HttpClient){}getProducts(查询:string):Observable{返回this.http.get('/api/product');}我不确定,但您不能将字符串的Observable分配给产品数组的Observable
Type 'Observable<string | Product[]>' is not assignable to type 'Observable<Product[]>'.
Type 'string | Product[]' is not assignable to type 'Product[]'.
Type 'string' is not assignable to type 'Product[]'