在模板中加入(mousedown)="onMouseDown($event)"和(click)="onClick($event)"函数,以取消文本选择。然后,在组件中声明这些函数,并在onMouseDown()函数里检查是否按下了Shift键。
import { Component } from '@angular/core';
@Component({
  selector: 'my-app',
  template: `
    
      Select this text with SHIFT
    
  `
})
export class AppComponent {
  private shifted = false;
  onMouseDown(event: MouseEvent) {
    this.shifted = event.shiftKey;
  }
  onClick(event: MouseEvent) {
    if (this.shifted) {
      // Do your thing with Shift+click here
    }
  }
}