AngularMaterial-mat-form-fieldpreventclickeventsusingstopPropagationisnotworking
创始人
2024-10-28 07:01:48
0

我们需要在mat-form-field上添加一个事件监听器,以捕捉click事件并阻止其冒泡。以下是一个示例代码:

import { Component, ViewChild, ElementRef, AfterViewInit } from '@angular/core';
import { MatFormField } from '@angular/material/form-field';

@Component({
  selector: 'app-example',
  template: `
    
      
    
  `,
})
export class ExampleComponent implements AfterViewInit {
  @ViewChild('formField') formField: MatFormField;

  constructor(private el: ElementRef) {}

  ngAfterViewInit() {
    this.formField._elementRef.nativeElement.onclick = (event: MouseEvent) => {
      event.stopPropagation();
    };
  }

  handleClick(event: MouseEvent) {
    event.stopPropagation();
    console.log('click event handled');
  }
}

在上面的例子中,我们首先获取mat-form-field的引用,然后在ngAfterViewInit()生命周期钩子中将一个click事件监听器添加到mat-form-field上。在该监听器中,我们调用stopPropagation()以阻止事件冒泡。我们还添加了另一个处理click事件的函数,以确保该事件被正确处理。

相关内容

热门资讯

透视软件!aapoker透视脚... 透视软件!aapoker透视脚本入口(透视)透视脚本入口(总是存在有挂);1、aapoker透视脚本...
透视有挂!德普之星辅助工具如何... 透视有挂!德普之星辅助工具如何打开(透视)私人局辅助器(都是存在有挂);1、起透看视 德普之星辅助工...
透视ai!德普之星透视免费(透... 透视ai!德普之星透视免费(透视)透视(好像有挂);1、德普之星透视免费系统规律教程、德普之星透视免...
辅助透视!aapoker怎么拿... 辅助透视!aapoker怎么拿好牌(透视)免费透视脚本(竟然是真的有挂);进入游戏-大厅左侧-新手福...
透视好牌!如何下载德普之星辅助... 透视好牌!如何下载德普之星辅助软件(透视)透视辅助软件激活码(一直有挂)1、如何下载德普之星辅助软件...
透视好友房!aapoker插件... 透视好友房!aapoker插件(透视)透视软件(其实真的是有挂)1、aapoker插件机器人多个强度...
透视黑科技!德普之星辅助软件(... 透视黑科技!德普之星辅助软件(透视)私人局辅助器(其实真的是有挂);1、首先打开德普之星辅助软件最新...
透视私人局!aapoker透视... 透视私人局!aapoker透视脚本(透视)辅助(原来真的是有挂)1、玩家可以在aapoker透视脚本...
透视有挂!aapoker ai... 透视有挂!aapoker ai插件(透视)辅助插件工具(原来真的是有挂)1、不需要AI权限,帮助你快...
透视游戏!德普之星怎么设置埋牌... 透视游戏!德普之星怎么设置埋牌(透视)私人局辅助器(切实有挂)1、任何德普之星怎么设置埋牌ai辅助神...