我正在尝试通过使用 rxjs 单击按钮通过 XHR 获取数据
document.getElementById('button')
.addEventListener('click', function() {
console.log("button clicked");
});
最佳答案
fromEvent(document.getElementById('button'), 'click').pipe(
switchMap(_ => ajax('yourEndpointUrl'))
).subscribe(
res => { // do stuff with response },
err => { // handle error }
);
关于javascript - 我想用 rxjs observable 替换 addEventListener,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58616719/