0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Angular 4.0+のモーダルウィンドウ外を押してもクローズにならない実装

Last updated at Posted at 2019-06-07

対象

・Angularの4系以上
・Angular Material使用

背景

Angular Materialのモーダルウィンドウのデフォルト設定では、モーダルウィンドウ以外の範囲をクリックするとクローズします。(モーダルウィンドウ以外の範囲をクリックすると、ウィンドウが閉じてしまいます。)
このデフォルト設定によって、ユーザーが意図しない動作を発動しやすくなるため、ウィンドウが閉じないように実装する必要がありました。

実装

app.component.ts

import { Component } from '@angular/core';
import { MatDialog } from '@angular/material';
import { DialogComponent } from './dialog/dialog.component';

@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
  styleUrls: [ './app.component.scss' ]
})
export class AppComponent  {
  constructor(
    public dialog: MatDialog
  ){}

  openDialog(){
   const dialogRef = this.dialog.open(DialogComponent, {
     width: '300px',
     height: '200px',
     disableClose: true//これによってモーダルウィンドウ範囲外のところをクリックしても閉じない
   });
  }
}

デモ→
https://stackblitz.com/edit/angular-doclj4?file=src%2Fapp%2Fapp.component.ts

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?