小编Or *_*yev的帖子

RxJs 自定义运算符无法访问“this”

我创建了一个访问的自定义运算符,this但它似乎总是未定义,即使我传递给this函数bind

自定义运算符

function shouldLoadNewOptimizationData() {
    return filter(function([p1,p2,p3]) {
       // some logic
       if(){
          this.store.dispatch()...
       }
    })
}
Run Code Online (Sandbox Code Playgroud)

自定义运算符用法

effect = createEffect(()=> this.actions$.pipe(
    ofType(//action type),
    withLatestFrom(
        //...selectors
    ),
    shouldLoadNewOptimizationData().bind(this),
    // more operators..
    )
)

Run Code Online (Sandbox Code Playgroud)

javascript rxjs typescript ngrx angular

6
推荐指数
2
解决办法
378
查看次数

标签 统计

angular ×1

javascript ×1

ngrx ×1

rxjs ×1

typescript ×1