Angularslide-toggle不响应确认弹窗后的操作
创始人
2024-10-29 16:00:56
0

在 slide-toggle 组件中添加一个 confirm 弹窗,当用户改变开关状态时弹出,等待用户确认后再更新数据。可以通过以下代码实现:

HTML:


  Slide Toggle

TypeScript:

import { MatDialog } from '@angular/material/dialog';
import { ConfirmDialogComponent } from './confirm-dialog/confirm-dialog.component';

export class MyComponent {
  isChecked = false;

  constructor(public dialog: MatDialog) {}

  confirmToggle(event: MatSlideToggleChange): void {
    const dialogRef = this.dialog.open(ConfirmDialogComponent, {
      data: { isChecked: event.checked }
    });

    dialogRef.afterClosed().subscribe(result => {
      if (result === 'confirm') {
        // 用户点击确认,更新数据
        this.isChecked = event.checked;
      } else {
        // 用户取消操作,还原开关状态
        this.isChecked = !event.checked;
      }
    });
  }
}

在 confirm-dialog.component.ts 中实现 ConfirmDialogComponent 组件,该组件可以通过 MatDialog 打开对话框,允许用户确认或取消操作。

HTML:

Confirm

Are you sure you want to toggle the switch?

TypeScript:

import { Component } from '@angular/core';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';

@Component({
  selector: 'app-confirm-dialog',
  templateUrl: './confirm-dialog.component.html'
})
export class ConfirmDialogComponent {
  constructor(
    public dialogRef: MatDialogRef,
    @Inject(MAT_DIALOG_DATA) public data: { isChecked: boolean }
  ) {}

  onCancelClick(): void {
    this.dialogRef.close();
  }
}

相关内容

热门资讯

必备攻略!竞技联盟透视插件,w... 《必备攻略!竞技联盟透视插件,wepoker透视最简单三个步骤,介绍教程(有挂辅助)》 wepoke...
透视ai代打!德普之星app安... 透视ai代打!德普之星app安卓版破解版(透视)一直存在有挂(详细辅助2025新版教程)1、超多福利...
透视安装!wepoker开脚本... 透视安装!wepoker开脚本视频(透视)竟然真的有挂(详细辅助安装教程);1、这是跨平台的黑科技,...
科技分享!wepoker手机助... 科技分享!wepoker手机助手,wepoker透视底牌脚本,新2025版(有挂攻略);支持2-10...
透视总结!poker worl... 透视总结!poker world辅助(透视)都是有挂(详细辅助2025新版);1、实时开挂更新:用户...
一分钟揭秘!约局吧德州有挂吗,... 一分钟揭秘!约局吧德州有挂吗,拱趴大菠萝万能挂图解,详细教程(有挂软件);致您一封信;亲爱拱趴大菠萝...
透视了解!wepoker透视脚... 透视了解!wepoker透视脚本(透视)都是存在有挂(详细辅助透牌教程)1、用户打开应用后不用登录就...
重大通报!aa poker辅助... 这是一款非常优秀的aa poker辅助 ia辅助检测软件,能够让你了解到aa poker辅助中牌率当...
查到实测辅助!hhpoker是... 您好,菠萝辅助器免费版的功能介绍这款游戏可以开挂的,确实是有挂的,需要了解加微【136704302】...
透视了解!wepoker有没有... 透视了解!wepoker有没有机器人(透视)果然存在有挂(详细辅助软件教程);1、系统规律教程、辅助...