[RxJS] Getting Input Text with Map

Posted Answer1215

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[RxJS] Getting Input Text with Map相关的知识,希望对你有一定的参考价值。

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));

 

以上是关于[RxJS] Getting Input Text with Map的主要内容,如果未能解决你的问题,请参考以下文章

RxJS实现“搜索”功能,这就是“可读”~

rxjs 入门--环境配置

使用 RxJS 获取“不是函数”错误

text RxJS提示和技巧

text Angular / Typescript / RxJs - 最佳实践

rxjs来啦