Typescript 3 Angular 7 StopPropagation and PreventDefault not working

后端 未结 3 1395
独厮守ぢ
独厮守ぢ 2021-02-18 18:16

I have a text input inside a div. Clicking on the input should set it to focus and stop the bubbling of the div click event. I\'ve tried the stopPropagation and

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-18 18:40

    You have two different events, one is mousedown and another is click.

    The e.stopPropagation() only works if both of the events are of the same kind.

    You can change the input like this to work as expected:

    
    

    Live example: https://stackblitz.com/edit/angular-material-basic-stack-55598740?file=app/input-overview-example.ts

提交回复
热议问题