0

I tried this solution

It did not help me.

Code:

@ViewChild('filter') filteru: ElementRef;

ngAfterViewInit() {

    this.dataSource = new ExampleDataSource(this.exampleDatabase);
    Observable.fromEvent(this.filteru.nativeElement, 'keyup')
      .debounceTime(150)
      .distinctUntilChanged()
      .subscribe(() => {
        if (!this.dataSource) { return; }
        this.dataSource.filter = this.filteru.nativeElement.value;
      });
  }

I import this:

import 'rxjs/add/observable/fromEvent';
3
  • any error popping up ? Commented Sep 28, 2017 at 9:54
  • are you sure that this is what you expect? (that it isn't undefinded) If it is undefinded, try adding .bind(this) after your subscription Commented Sep 28, 2017 at 10:59
  • If your could replicate the issue in a plunkr, that would help a lot Commented Sep 28, 2017 at 11:00

1 Answer 1

1

I guess you might have missed the imports

import 'rxjs/add/observable/fromEvent';
import 'rxjs/add/operator/debounceTime';
import 'rxjs/add/operator/distinctUntilChanged';
import {Observable} from 'rxjs/Observable';

Working Stackblitz link

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.