我复制了一些 Angular 官方页面上的代码,但是 Visual Code 显示了一个错误:
这一行出现了错误:
map((e: KeyboardEvent) => e.target.value),
错误。
Property 'value' does not exist on type 'EventTarget'.
以下是来自 Angular 官方网站 的代码:
import { fromEvent } from 'rxjs';
import { ajax } from 'rxjs/ajax';
import { map, filter, debounceTime, distinctUntilChanged, switchMap } from 'rxjs/operators';
const searchBox = document.getElementById('search-box');
const typeahead = fromEvent(searchBox, 'input').pipe(
map((e: KeyboardEvent) => e.target.value),
filter(text => text.length > 2),
debounceTime(10),
distinctUntilChanged(),
switchMap(() => ajax('/api/endpoint'))
);
typeahead.subscribe(data => {
// Handle the data from the API
});
EventTarget是什么类型? - Sachin Gupta