angular实现dialog弹窗

说明:

angular实现dialog弹窗

效果图:

step1:E:\projectgood\ajnine\untitled4\src\app\apple\apple.component.html

xml 复制代码
<button mat-button (click)="openDialog()">Open dialog</button>

step2:E:\projectgood\ajnine\untitled4\src\app\apple\apple.component.ts

typescript 复制代码
import {Component, inject} from '@angular/core';
import {MatButton, MatButtonModule} from '@angular/material/button';
import {MatDialog, MatDialogModule} from '@angular/material/dialog';
import {DialogContentExampleDialog} from './DialogContentExampleDialog';


@Component({
  selector: 'app-apple',
  standalone: true,
  imports: [
    MatButton, MatButtonModule, MatDialogModule
  ],
  templateUrl: './apple.component.html',
  styleUrl: './apple.component.css'
})
export class AppleComponent {
  readonly dialog = inject(MatDialog);


  openDialog() {
    const dialogRef = this.dialog.open(DialogContentExampleDialog);

    dialogRef.afterClosed().subscribe(result => {
      console.log(`Dialog result: ${result}`);
    });
  }


}

step3:E:\projectgood\ajnine\untitled4\src\app\apple\dialog-content-example-dialog.html

xml 复制代码
<h2 mat-dialog-title>Install Angular</h2>
<mat-dialog-content class="mat-typography">
  <h3>Develop across all platforms</h3>
  <p>{{ cancelString }}</p>
  <p>{{ sureString }}</p>
</mat-dialog-content>
<mat-dialog-actions align="end">
  <button mat-button [mat-dialog-close]="cancelString">Cancel</button>
  <button mat-button [mat-dialog-close]="sureString">Install</button>
</mat-dialog-actions>

step4:E:\projectgood\ajnine\untitled4\src\app\apple\DialogContentExampleDialog.ts

typescript 复制代码
import {ChangeDetectionStrategy, Component, OnInit} from '@angular/core';
import {MatDialogModule} from '@angular/material/dialog';
import {MatButtonModule} from '@angular/material/button';

@Component({
  selector: 'dialog-content-example-dialog',
  templateUrl: 'dialog-content-example-dialog.html',
  standalone: true,
  imports: [MatDialogModule, MatButtonModule],
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class DialogContentExampleDialog implements OnInit{
  cancelString :string=''
  sureString :string=''


  ngOnInit(): void {
    this.cancelString="鲨鱼哟"
    this.sureString="昊昊超体"
  }

}

end

相关推荐
前端之虎陈随易1 天前
2年没用Nodejs了,Bun很香
linux·前端·javascript·vue.js·typescript
好运的阿财1 天前
OpenClaw工具拆解之host_workspace_write+host_workspace_edit
前端·javascript·人工智能·机器学习·ai编程·openclaw·openclaw工具
XiYang-DING1 天前
JavaScript
开发语言·javascript·ecmascript
空中海1 天前
02 React Native状态、导航、数据流与设备能力
javascript·react native·react.js
空中海1 天前
02 状态、Hooks、副作用与数据流
开发语言·javascript·ecmascript
空中海1 天前
04 React Native工程化、质量、发布与生态选型
javascript·react native·react.js
杨超凡1 天前
豆包收费了?我特么自己用“意念”搓了一个!
javascript
threelab1 天前
Three.js 咖啡杯烟雾效果 | 三维可视化 / AI 提示词
开发语言·javascript·人工智能
Heo1 天前
14_React 中的更新队列 updateQueue
前端·javascript·面试