我用的是Angular RXJS,我有多个行为主体,

提前谢谢.

  private CategorySubject = new BehaviorSubject<number>();
  //CategorySubject = new Subject<number>();
  //CategorySubject = new BehaviorSubject<number>(null);
  public CategoryAction$ = this.CategorySubject.asObservable();

  //pageIndex Subject
  private pageIndexSubject = new BehaviorSubject<number>(1);
  public pageIndexAction$ = this.pageIndexSubject.asObservable();

  //Search/filter Subject
  private searchSubject = new BehaviorSubject<string>('');
  public searchAction$ = this.searchSubject.asObservable();

 Posts$ = combineLatest([
    this.pageIndexAction$,
    this.searchAction$
    this.CategoryAction$
  ]).pipe()

推荐答案

启用strictNullChecks后,可以将Behavior Subject的类型指定为BehaviorSubject<number|null>,也可以使用普通Subject<number>startWithcombineLatest中发出初始null值:

 private CategoryAction$ = new Subject<number>();
 
 ...
 
 Posts$ = combineLatest([
    this.pageIndexAction$,
    this.searchAction$
    this.CategoryAction$.pipe(startWith(null))
  ]).pipe()

Angular相关问答推荐

如何在HTML外部项目中使用Web组件(以17角创建)

如何在ANGLING v17中使用鞋带样式组件?

Primeng:安装ANGLE 16.2.0版本

无法在Mat-SideNav中绑定模式

Ngrx Select 器返回部分对象

ANGLE v16独立组件不能与拦截器一起工作?

为什么初始化值为 1 的BehaviorSubject 不能分配给类型number?

如何从2个api获取数据并查看Angular material 表中的数据?

Angular p-triStateCheckbox for each Select 更改不同的 colored颜色

VSCode / Angular 应用程序未完全启动

无法在 Angular 中使用 CryptoJS 正确加密

检测父元素是否绑定到 Angular 中的子元素 @Output

如何在Cypress 测试中切换 Angular 选项卡

初始化所有子类后的Angular 2生命周期钩子是什么?

如何在 Angular 2 中创建可重用的动画

Angular 2从assets文件夹加载CSS背景图像

Angular:找不到不同的支持对象[object Object]

安装特定版本的 ng cli

Lint 错误:实现生命周期挂钩接口

如何在 Angular Material 中设置图标的 colored颜色 ?