zl程序教程

您现在的位置是:首页 >  后端

当前栏目

[RxJS] Getting Input Text with Map

Map with Text input Rxjs Getting
2023-09-14 08:59:20 时间

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/rxjs@5.0.0-beta.1/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));