我正在使用IE11和Angular 4,试图收听粘贴事件。我想尝试在用户选择Ctrl + V时将文本放入文本区域,但是listen事件永远不会触发。
我的HTML:
public text: string = '';
@ViewChild('textArea', { read: ElementRef }) testElement: ElementRef;
ngAfterViewInit() {
this.isIEOrEdge = /msie\s|trident\/|edge\//i.test(window.navigator.userAgent);
if (this.isIEOrEdge) {
console.log('Element' , this.testElement.nativeElement);
this.renderer.listen(this.testElement.nativeElement, 'paste', () => {
console.log('pasting');
this.InsertNewRowsBeforePaste.bind(this);
});
}
}
InsertNewRowsBeforePaste(event) {
// gets data from clipboard and converts it to an array (1 array element for each line)
let clipboardData = event.clipboardData || event.originalEvent['clipboardData'].getData('text');
if (!clipboardData) {
clipboardData = window['clipboardData'].getData('Text');
}
this.text = clipboardData;
}
我的打字稿:
// READ VALUE
result = advApi.RegQueryValueExA(key.handle.deref(), valueName, null, pKeyType, value,
pKeyDataLength);