您好我正在使用angular2,我正在尝试使用按钮和按钮单击方法从页面调用打印屏幕功能。
我想要做的是,一旦我点击按钮,我必须为按钮按下事件调用hostlistener,并截取整个屏幕的截图,而不仅仅是窗口。
我的代码如下: 在screenshot.component.html页面中:
<button (click) ="onkeydownHandler($event)">Capture</button>
screenshot.component.ts文件中的:
export class ScreenshotComponent{
onkeydownHandler(event: MouseEvent) {
@HostListener('window:keyup', event.keyCode='44')
keyEvent(event: KeyboardEvent) {
console.log(event);
}
}
}
由于printscreen按钮的键码是44,我使用该代码并尝试调用printscreen按钮的操作。 尝试执行此操作时,我收到以下异常:
ReferenceError: keyEvent is not defined
at ScreenshotComponent.onkeydownHandler (screenshot.component.ts:14)
at ChangeDetector_ScreenshotComponent_0.handleEventInternal (viewFactory_ScreenshotComponent:30)
at ChangeDetector_ScreenshotComponent_0.AbstractChangeDetector.handleEvent (angular2.dev.js:9568)
at AppView.triggerEventHandlers (angular2.dev.js:10246)
at eval (viewFactory_ScreenshotComponent:84)
at angular2.dev.js:14068
at angular2.dev.js:13496
at ZoneDelegate.invoke (angular2-polyfills.js:332)
at Object.onInvoke (angular2.dev.js:2111)
at ZoneDelegate.invoke (angular2-polyfills.js:331)
这是正确的方法吗?有人可以帮忙吗?