zoukankan      html  css  js  c++  java
  • angular5 open modal

    1. 在component 中打开modal,点击close 关闭modal

    html:

    <div class="modal-header " >
      <h4 class="modal-title">Message</h4>
      <button type="button" class="close" aria-label="Close" (click)="activeModal.dismiss('Cross click')">
        <span aria-hidden="true">×</span>
      </button>
    </div>
    <div id="modal_content" class="modal-body" [innerHTML]="modal_info">
    
    </div>
    <div class="modal-footer">
      <button type="button" class="btn btn-outline-dark" (click)="activeModal.close('Close click')">Close</button>
    </div>
    

     component:

     backdrop: 'static' : 点击modal 外的空白处,不会关闭modal;
     keyboard: false: 使按ESC 不会关闭modal
    import {Component, OnInit, Input, Output} from '@angular/core';
    import {NgbModal, NgbActiveModal} from '@ng-bootstrap/ng-bootstrap';
    import {NgbModalRef} from '@ng-bootstrap/ng-bootstrap/modal/modal-ref';
    
    @Component({
      selector: 'app-modal-dialog',
      templateUrl: './modal-dialog.component.html',
      styleUrls: ['./modal-dialog.component.css']
    })
    export class ModalDialogComponent implements OnInit {
    
      modal_info: string;
      modalRef: NgbModalRef;
      constructor(public activeModal: NgbActiveModal,
                  private modalService: NgbModal) {
      }
    
      ngOnInit() {
      }
    
      openModal(modal_info: string): void {
        // this.modal_info = modal_info;
    
        // const modalRef = this.modalService.open(ModalDialogComponent);
        this.modalRef = this.modalService.open(ModalDialogComponent, { backdrop: 'static', keyboard: false});
        this.modalRef.componentInstance.modal_info = modal_info;
      }

    2. 将modal做成一个遮罩层,调用modalRef 关闭 modal

    this.modalRef = this.modalService.open(ModalDialogComponent, { backdrop: 'static', keyboard: false}); 
    这行代码能打开一个modal,由于这次是使用modal来制作遮罩层,所以我们不需要在html 中写入任何的html.
    import {Component, OnInit, Input, Output} from '@angular/core';
    import {NgbModal, NgbActiveModal} from '@ng-bootstrap/ng-bootstrap';
    import {NgbModalRef} from '@ng-bootstrap/ng-bootstrap/modal/modal-ref';
    
    @Component({
      selector: 'app-modal-dialog',
      templateUrl: './modal-dialog.component.html',
      styleUrls: ['./modal-dialog.component.css']
    })
    export class ModalDialogComponent implements OnInit {
    
      modal_info: string;
      modalRef: NgbModalRef;
      constructor(public activeModal: NgbActiveModal,
                  private modalService: NgbModal) {
      }
    
      ngOnInit() {
      }
    // 打开一个空的modal,即遮罩层
      openModal(modal_info: string): void {
        // this.modal_info = modal_info;
    
        // const modalRef = this.modalService.open(ModalDialogComponent);
        this.modalRef = this.modalService.open(ModalDialogComponent, { backdrop: 'static', keyboard: false});
        this.modalRef.componentInstance.modal_info = modal_info;
      }
    // 用于在其他component中关于遮罩层
      closeModal(): void {
         this.modalRef.close();
      }
  • 相关阅读:
    PHP输出中文乱码的问题(转)
    phpmyadmin导出数据库为什么是php文件
    phpmyadmin登陆提示#2002 无法登录 MySQL 服务器和设置自增
    phpMyAdmin配置及 错误 缺少 mysqli 扩展。请检查 PHP 配置
    利用eclipse开发php<转>
    apache 2.4 You don't have permission to access / on this server
    (转)如果“打开方式”里面没有想要的打开方式,怎样创建一种文件打开方式?
    (转)安装 Apache 出现 <OS 10013> 以一种访问权限不允许的方式做了一个访问套接字的尝试
    关于ISAPI和CGI限制,这个要设为允许
    Sqlserver数据库日志太大如何快速删除
  • 原文地址:https://www.cnblogs.com/wanthune/p/8973375.html
Copyright © 2011-2022 走看看