By default, Inputs will push input events into the stream. This lesson shows you how to use map
to convert the input event into the text you actually want.
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width"> <script src="https://npmcdn.com/@reactivex/[email protected]/dist/global/Rx.umd.js"></script> <title>JS Bin</title> </head> <body> <input type="text" id="input"> </body> </html>
const input = document.querySelector(‘#input‘); const input$ = Observable.fromEvent(input, ‘input‘) .map(event => event.target.value); input$ .subscribe((x)=> console.log(x));
时间: 2024-11-05 22:04:18