저는 TypeScript를 처음 접했고 솔직히이 잘못을 저 지르려고합니다. 하지만 ... 사용자가 타이핑을 멈추었을 때 "알리는"텍스트 상자 용 "KeyUp Listener"를 만들려고합니다.ReferenceError : HTMLElement가 TypeScript에 정의되어 있지 않습니다.
Exception: Call to Node module failed with error: Prerendering failed because of error: ReferenceError: HTMLElement is not defined
등록 :
// 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() { }
}
알리미 보이는 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")
}
}
죄송합니다 ... 이미 TS.CONFIG에 있습니다 ... 도움을 주셔서 감사합니다. –
또한 "올바른 방법으로"Listener "코드가 보이나요? –
이제 코드에 대해 자세히 살펴 보았습니다. 두 가지 질문이 있습니다. (유니버설에 익숙하지 않아서 내 질문이 많이 잘못되었을 수도 있습니다.) 청취자가 주유기 (구성 요소 및/또는 다른 서비스에 서비스로 주입 될 수있는 것을 의미)하는 이유는 무엇입니까? 1 초 이내에 keyUp 이벤트가 캡처되지 않으면 청취자의 의도가 방출됩니까? – Picci