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事件的函数,以确保该事件被正确处理。

相关内容

热门资讯

透视详情!wpk有作弊吗,wp... 透视详情!wpk有作弊吗,wpk刷入池率脚本-确实有辅助插件(哔哩哔哩)1、任何透视是真的假的的玩家...
透视辅助!如何下载wpk透视版... 透视辅助!如何下载wpk透视版,wpk刷入池率脚本-一直真的有辅助软件(哔哩哔哩)1、下载好正确养号...
透视开挂!hhpoker有没有... 透视开挂!hhpoker有没有辅助,德州hhpoker脚本-一贯一直都是有辅助攻略(哔哩哔哩)1、在...
透视开挂!wpk模拟器,wpk... 透视开挂!wpk模拟器,wpk软件是正规的吗-都是一直都是有辅助教程(哔哩哔哩)1、不需要AI权限,...
透视详细!wpk显示有作弊,w... 透视详细!wpk显示有作弊,wpk软件是正规的吗-确实真的是有辅助工具(哔哩哔哩)破解侠是真的助透视...
透视关于!wpk系统是否存在作... 透视关于!wpk系统是否存在作弊行为,wpk透视是真的假的-都是有辅助技巧(哔哩哔哩)透视关于!wp...
透视揭幕!wpk透视插件,wp... 透视揭幕!wpk透视插件,wpk显示有作弊-切实真的是有辅助攻略(哔哩哔哩)1、下载好透视辅助下载之...
透视解密!hhpoker有辅助... 透视解密!hhpoker有辅助吗,hhpoker脚本下载-都是真的有辅助神器(哔哩哔哩)1、每一步都...
透视解谜!we poker辅助... 透视解谜!we poker辅助器下载,wejoker透视方法-果然是有辅助神器(哔哩哔哩)1、破解器...
透视曝光!wepoker高级辅... 透视曝光!wepoker高级辅助,wepoker辅助是真的吗-原来是有辅助软件(哔哩哔哩)1、脚本辅...