I'm new to TypeScript, and frankly, I may be doing this wrong. But...I'm trying to create a "KeyUp Listener" for text-boxes that will "notify" when the user has stopped typing. However, when I try to register the class, I get the following error:
Exception: Call to Node module failed with error: Prerendering failed because of error: ReferenceError: HTMLElement is not defined
REGISTRATION:
// MODULES
import { NgModule } from '@angular/core';
import { RouterModule } from '@angular/router';
import { UniversalModule } from 'angular2-universal';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
// COMPONENTS
import { AppComponent } from './components/app/app.component'
import { HeaderComponent } from './components/shared/components/shared-header.component';
import { SampleIndexComponent } from './components/samples/sample.index.component';
import { SampleFormComponent } from './components/samples/sample.form.component';
import { StatusFilterComponent } from './components/samples/filters/status-filter.component';
import { AuthorFilterComponent } from './components/samples/filters/author-filter.component';
// LISTENERS
import { TextboxKeyUpListener } from "./components/shared/services/textbox.keyup.listener";
@NgModule({
bootstrap: [ AppComponent ],
declarations: [
AppComponent,
HeaderComponent,
SampleIndexComponent,
StatusFilterComponent,
AuthorFilterComponent,
SampleFormComponent
],
imports: [
UniversalModule, // <-- Must be first import. This automatically imports BrowserModule, HttpModule, and JsonpModule too.
FormsModule,
ReactiveFormsModule,
RouterModule.forRoot([
{ path: '', redirectTo: 'samples', pathMatch: 'full' },
{ path: 'samples', component: SampleIndexComponent },
{ path: 'form', component: SampleFormComponent },
{ path: '**', redirectTo: 'samples' }
])
],
providers: [AuthorFilterNotifier, StatusFilterNotifier, TextboxKeyUpListener]
})
export class AppModule
{
constructor() { }
}
NOTIFIER LOOKS LIKE:
// MODULES
import { Injectable, Inject } from '@angular/core';
import { Subject } from 'rxjs/Subject';
@Injectable()
export class TextboxKeyUpListener {
// CONSTRUCTORS
constructor(private textbox: HTMLInputElement)
{
this.init();
}
// PROPERTIES - private
private typingTimer: NodeJS.Timer;
private typingTimerInterval: number = 1000;
private notifyDoneTyping = new Subject<string>();
// PROPERTIES - public
public notifyDoneTyping$ = this.notifyDoneTyping.asObservable();
// METHODS - public
private keyUp(ev: KeyboardEvent)
{
global.clearTimeout(this.typingTimer);
if(this.textbox.value)
this.typingTimer = global.setTimeout(this.notify, this.typingTimerInterval);
}
// METHODS - private
private init()
{
this.textbox.onkeyup = this.keyUp;
}
private notify()
{
this.notifyDoneTyping.next(this.textbox.value);
console.log("Done Typing")
}
}