Ceri Westcott
Ceri Westcott

Reputation: 300

cannot read pipe of undefined when using debounceTime

I am trying to cause an event to fire when an input box has no value typed into it after 1 second.

 @ViewChild('input') input;

 ngAfterViewInit() {
        this.input
           .valueChanges
           .pipe(
               debounceTime(1000),
                distinctUntilChanged()
           )
            .subscribe(value => {
                if(value) {
                     //do stuff
                }
            })
    }


vendor.js:70063 ERROR TypeError: Cannot read property 'pipe' of undefined
    at SimpleDomainSearchComponent.ngAfterViewInit (main.js:8036)
    at callHook (vendor.js:68662)
    at callHooks (vendor.js:68626)
    at executeInitAndCheckHooks (vendor.js:68566)
    at refreshView (vendor.js:75092)
    at refreshComponent (vendor.js:76493)
    at refreshChildComponents (vendor.js:74733)
    at refreshView (vendor.js:75068)
    at refreshDynamicEmbeddedViews (vendor.js:76404)
    at refreshView (vendor.js:75039)
defaultErrorLogger @ vendor.js:70063

I have followed different tutorials to find the cause of this but I cannot, I have changed the input to FormControl and that has still caused the pipe to be undefined. the input isn't null, ive debugged it.

Upvotes: 0

Views: 210

Answers (1)

Yasser Nascimento
Yasser Nascimento

Reputation: 1381

Try to use FormControl without using ViewChild.

<input type="text" [formControl]="input">
input = new FormControl('');

With that you will have access to the valueChanges prop.

Upvotes: 2

Related Questions