Javascript ActivatedRoute.paramMap.switchMap错误

Javascript ActivatedRoute.paramMap.switchMap错误,javascript,angular,typescript,rxjs,Javascript,Angular,Typescript,Rxjs,在我的组件的ngOnInit方法中,以下行产生错误 this.products$ = this.route.paramMap.switchMap((params: ParamMap) => this.getProductsForType(params.get('type'))); 这是产生的错误: BrandComponent_Host.ngfactory.js? [sm]:1 ERROR TypeError: this.route.paramMap.switchMap is no

在我的组件的ngOnInit方法中,以下行产生错误

this.products$ = this.route.paramMap.switchMap((params: ParamMap) =>
  this.getProductsForType(params.get('type'))); 
这是产生的错误:

BrandComponent_Host.ngfactory.js? [sm]:1 ERROR TypeError: this.route.paramMap.switchMap is not a function
at BrandComponent.ngOnInit (brand.component.ts:22)
at checkAndUpdateDirectiveInline (core.js:12369)
at checkAndUpdateNodeInline (core.js:13893)
at checkAndUpdateNode (core.js:13836)
at debugCheckAndUpdateNode (core.js:14729)
at debugCheckDirectivesFn (core.js:14670)
at Object.eval [as updateDirectives] (BrandComponent_Host.ngfactory.js? [sm]:1)
at Object.debugUpdateDirectives [as updateDirectives] (core.js:14655)
at checkAndUpdateView (core.js:13802)
at callViewAction (core.js:14153)
这是一个组件:

export class BrandComponent implements OnInit {
  private products:Product[];
  private products$: Observable<Product[]>;

  constructor(private route:ActivatedRoute,
    private brandService: BrandService) { }

  ngOnInit() {    
    this.products$ = this.route.paramMap.switchMap((params: ParamMap) =>
      this.getProductsForType(params.get('type'))); 
  }

  private getProductsForType(type) {
    console.log('BrandComponent.getProductsForType() called')
    return this.brandService.getProductsForType(type);
  }

}
导出类BrandComponent实现OnInit{
私人产品:产品[];
私人产品美元:可观察;
构造函数(专用路由:ActivatedRoute,
私人品牌服务:品牌服务){}
ngOnInit(){
this.products$=this.route.paramMap.switchMap((params:paramMap)=>
this.getProductsForType(params.get('type'));
}
私有getProductsForType(类型){
console.log('调用了BrandComponent.getProductsForType()')
返回此.brandService.getProductsForType(类型);
}
}
目前,BrandService.getProductsForType()方法正在返回一个空数组:

@Injectable()
export class BrandService {
  private productsUrl:string = '/api/products/all';
  private products:Product[];

  constructor(private http:HttpClient,
    private dataService:DataService) { }

  public getProductsForType(type:string)  : Observable<Product[]> {
    console.log('BrandService.getProductsForType() called')
    // return this.dataService.getProductsForType(type);
    return of([])
  }
}
@Injectable()
出口级品牌服务{
private-productsUrl:string='/api/products/all';
私人产品:产品[];
构造函数(私有http:HttpClient,
私有数据服务:数据服务){}
publicGetProductsForType(类型:string):可观察{
console.log('调用了BrandService.getProductsForType()')
//返回此.dataService.getProductsForType(类型);
返回([])
}
}

您需要导入
开关映射
操作符才能使用它。在文件顶部添加以下行,其中包含其他导入:

import 'rxjs/add/operator/switchMap';

您是否导入了
开关映射
操作符<代码>导入'rxjs/add/operator/switchMap'宾果!谢谢。我会加上它作为回答