directive click outside angular 6

前端 未结 4 2186
广开言路
广开言路 2021-02-19 04:01

I upgraded my Angular from 4 to 6, and consequently had a problem with my click-off policy, it stopped working on all components.

my directive:



        
4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-19 04:16

    Run the inside NgZone.

    Example:

    export class AppComponent {
      opened: boolean = false;
    
      constructor(private ngZone: NgZone) {
      }
    
      closeOutsideSidenav(e) {
        this.ngZone.run(() => {
          this.opened = !this.opened;
        })
      }
    }
    

    I added my code to stackblitz. https://stackblitz.com/edit/angular-gyhtym (click outside of the "Highlight Me!")

提交回复
热议问题