1
votes

I have application based on angular 6.10 and rxjs 6.3. I also have a problem :(

This is my code:

  public keyUp = new Subject<string>();
const observable = this.keyUp
      .pipe(
         map(value => (event.target as HTMLInputElement).value),
         debounceTime(300),
         distinctUntilChanged(),
         flatMap((search) => {
           return of(search).pipe(delay(300));
         }),
      )
      .subscribe((data) => {
        this.filter = data;
        this.onFilterChange(this.filter);
      });

This code is merged from rxjs 5.5.6 by me - unfortunately I dont remember the older version. This is error for actual version error:

ERROR TypeError: Object(...) is not a function
    at MergeMapSubscriber.eval [as project] (framework.js:232)
    at MergeMapSubscriber._tryNext (mergeMap.js:128)
    at MergeMapSubscriber._next (mergeMap.js:118)
    at MergeMapSubscriber.Subscriber.next (Subscriber.js:92)
    at DistinctUntilChangedSubscriber._next (distinctUntilChanged.js:104)
    at DistinctUntilChangedSubscriber.Subscriber.next (Subscriber.js:92)
    at DebounceTimeSubscriber.debouncedNext (debounceTime.js:101)
    at AsyncAction.dispatchNext (debounceTime.js:117)
    at AsyncAction._execute (AsyncAction.js:119)
    at AsyncAction.execute (AsyncAction.js:94)
1
I've never seen this typo (event.target as HTMLInputElement)... Why not simply map((value: Event) => value.target.value), ? Also, your keyUp is declared of type <string> which doesn't seem to be correct because you manage an Event, not a string. Also const observable = is not necessary until you subscribe to it later. - dun32
Okay but still the problem exist - user3577896
Please, can you update the code ? - dun32

1 Answers

1
votes

For me, this error happened when my import was not correct.

My import was like:

import { tap } from 'rxjs/operators';

The correct version is:

import { tap } from 'rxjs/operators/tap';

Please check how you imported mergeMap operator.