How to get mouseup outside of the component in Angular 2

后端 未结 4 1887
一生所求
一生所求 2021-01-12 01:03

I have a abc component (part of the page). It has an event mouseup.

@Component({
    selector: \'abc-component\'
})
@View({
    
4条回答
  •  不思量自难忘°
    2021-01-12 01:24

    A bit old but this might help somebody, you can use Observable.fromEvent too:

    ngOnInit() {
      this.mouseUpSubscription = Observable.fromEvent(window, "mouseup")
        .throttleTime(30) // throttle time in ms, optional
        .subscribe(res => {
          this.mouseUpHandler(res);
        });
    }
    
    ngOnDestroy() {
      this.mouseUpSubscription.unsubscribe();
    }
    

提交回复
热议问题