我正在尝试使用Ngrx的combineLatest在导航结束时执行操作,或者在另一个订阅中执行状态更改。在我的组件ngOnInit()
中,我有:
ngOnInit(): void {
const routerSub = this.router.events.subscribe();
const patientSub = this.patientService.state.subscribe();
Observable.combineLatest(routerSub, patientSub, (routerEvent, patientState) => {
console.log(routerEvent);
console.log(patientState);
});
}
但是,routerSub
上有编译错误:
“订阅”类型的参数不能分配给类型的参数 'IScheduler |可订阅| PromiseLike | ArrayLike | ((...值:任何[])=> {})'
我应该为combineLatest
提供什么路由器状态?
答案 0 :(得分:2)
combineLatest组合ngOnInit(): void {
const routerSub = this.router.events;
const patientSub = this.patientService.state;
Observable.combineLatest(routerSub, patientSub, (routerEvent, patientState) => {
console.log(routerEvent);
console.log(patientState);
})
.subscribe();
}
并在所有可观察数据都具有要发出的最新值时发出最新值。所以你需要传入observable,而不是订阅。所以你的代码应该改为
def remove_nested_parens(input_str):
"""Returns a copy of 'input_str' with any parenthesized text removed. Nested parentheses are handled."""
result = ''
paren_level = 0
for ch in input_str:
if ch == '(':
paren_level += 1
elif (ch == ')') and paren_level:
paren_level -= 1
elif not paren_level:
result += ch
return result
remove_nested_parens('example_(extra(qualifier)_text)_test(more_parens).ext')