1. 打开弹窗的点击事件

project.component.html

<button mat-icon-button class="action-button" (click)="editDialog(project)">
<mat-icon>create</mat-icon>编辑
</button>
<button mat-mini-fab color="warn" class="add-project" (click)="openDialog()">
<mat-icon>add</mat-icon>
</button>

project.component.ts

import { Component, OnInit } from '@angular/core';
import { MatDialog } from '@angular/material';
import { NewProjectComponent } from '../new-project/new-project.component'; @Component({
selector: 'app-project',
templateUrl: './project.component.html',
styleUrls: ['./project.component.scss']
})
export class ProjectComponent implements OnInit { projects=[
{
"name":'企业协作平台',
"desc":'这是一个企业内部项目',
"coverImg":'assets/img/covers/0.jpg'
},
{
"name":'员工管理平台',
"desc":'这是一个企业内部项目',
"coverImg":'assets/img/covers/1.jpg'
}
];
constructor(public dialog:MatDialog) { } ngOnInit() {
} // 新建项目
openDialog(){
const dialogRef = this.dialog.open(NewProjectComponent, {
width: '250px'
}); dialogRef.afterClosed().subscribe(result => {
console.log('The dialog was closed',result);
});
} // 编辑项目
editDialog(data){
const dialogRef = this.dialog.open(NewProjectComponent,{
width:'250px',
data:data
});
dialogRef.afterClosed().subscribe(result=>{
console.log('The dialog was closed',result);
})
} }

2. 弹窗

new-project.component.html

<h1 mat-dialog-title>新建项目</h1>
<div mat-dialog-content>
<mat-form-field>
<input matInput [(ngModel)]="project.name" placeholder="项目名称">
</mat-form-field>
<mat-form-field>
<input matInput [(ngModel)]="project.desc" placeholder="项目描述">
</mat-form-field>
</div>
<div mat-dialog-actions>
<button mat-raised-button (click)="onNoClick()">关闭</button>
<button mat-raised-button [mat-dialog-close]="project" cdkFocusInitial color="primary">保存</button>
</div>

new-project.component.ts

import { Component, OnInit, Inject } from '@angular/core';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material'; @Component({
selector: 'app-new-project',
templateUrl: './new-project.component.html',
styles: []
})
export class NewProjectComponent implements OnInit { project:Object;
constructor(
public dialogRef:MatDialogRef<NewProjectComponent>,
@Inject(MAT_DIALOG_DATA) public data
) { } ngOnInit() {
this.project = this.data||{};
} onNoClick(){
this.dialogRef.close();
} }

3. 特别注意:new-project组件是一个服务。在project.module.ts中必须写入entryComponent中,否则会报错

import { NgModule } from '@angular/core';
import { ProjectComponent } from './project/project.component';
import { SharedModule } from '../shared/shared.module';
import { NewProjectComponent } from './new-project/new-project.component'; @NgModule({
imports: [
SharedModule
],
declarations: [ProjectComponent, NewProjectComponent],
entryComponents:[
NewProjectComponent
]
})
export class ProjectModule { }

angular material dialog应用的更多相关文章

  1. [转]Angular 4|5 Material Dialog with Example

    本文转自:https://www.techiediaries.com/angular-material-dialogs/ In this tutorial, we're going to learn ...

  2. Angular 2 to Angular 4 with Angular Material UI Components

    Download Source - 955.2 KB Content Part 1: Angular2 Setup in Visual Studio 2017, Basic CRUD applicat ...

  3. Angular Material design设计

    官网: https://material.io/design/ https://meterial.io/components 优秀的Meterial design站点: http://material ...

  4. [转]Angular4 引用 material dialog时自定义对话框/deep/.mat-dialog-container

    本文转自:https://blog.csdn.net/qq_24078843/article/details/78560556 版权声明:本文为博主原创文章,未经博主允许不得转载. https://b ...

  5. Angular Material & Hello World

    前言 Angular Material(下称Material)的组件样式至少是可以满足一般的个人开发需求(我真是毫无设计天赋),也是Angular官方推荐的组件.我们通过用这个UI库来快速实现自己的i ...

  6. 手势模型和Angular Material的实现

    iPhone的出现让手势操作大为流行,也使得手势编程成为开发人员的挑战. 拟物设计也把手势编程纳入在内,大概也想制定一个在交互模型标准.现阶段因为MD还在预发布阶段,因此还只实现了单点手势(一个指头) ...

  7. 【转】Android新组件Material Dialog,SwipeRefreshLayout,ListPopupWindow,PopupMenu等

    朝花夕拾----新组件的学习和使用 分类: Android UI2015-06-26 11:31 440人阅读 评论(0) 收藏 举报 uidialogMaterial   目录(?)[-] Mate ...

  8. Material使用11 核心模块和共享模块、 如何使用@angular/material

    1 创建项目 1.1 版本说明 1.2 创建模块 1.2.1 核心模块 该模块只加载一次,主要存放一些核心的组件及服务 ng g m core 1.2.1.1 创建一些核心组件 页眉组件:header ...

  9. Angular Material 白天模式和黑夜模式

    Material design调色板 https://www.materialpalette.com/ 明暗:虽然颜色不变,但是针对白天黑夜有做不同处理. 叠加:对话框,弹出菜单,事先是没有加载的.是 ...

随机推荐

  1. 利用js 获取ip和地址

    1.引用第三方js<script src="http://pv.sohu.com/cityjson?ie=utf-8"></script> 2.     I ...

  2. UITableViewCell的prepareForReuse方法

    cell被重用怎样提前知道? 重写cell的prepareForReuse官方头文件里有说明.当前已经被分配的cell假设被重用了(一般是滚动出屏幕外了),会调用cell的prepareForReus ...

  3. 一种基于RGB空间的对照度增强的filter

    今天看前辈博客的时候看到一种新的基于RGB颜色空间的image contrast enhance filter 流浪的鱼link: http://blog.csdn.net/jia20003/arti ...

  4. 一入python深似海--对象的属性

    Python中一切皆是对象,每一个对象都能够有多个属性.Python是怎样管理这些属性呢?我们来探讨一下. 属性的__dict__系统 对象的属性包括两部分:类属性和对象属性.对象的属性可能来自于其类 ...

  5. 第一个WPF

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  6. Shiro结合Redis解决集群中session同步问题

    pom.xml文件中引入redis的依赖 在application.xml配置redis: <bean id="jedisConnectionFactory" class=& ...

  7. 用SSL保Samba安全

    用SSL保Samba安全          在企业中用Samba做为文件服务器是非常容易的事了,那如何保证存储数据的安全,如何保证数据传输的安全呢?我以前介绍过通过Samba安全级别和加装防病毒软件在 ...

  8. 竖向 两级手风琴 TAB 栏

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  9. Linux 时区的修改

    Linux 时区的修改 1. CentOS和Ubuntu的时区文件是/etc/localtime,但是在CentOS7以后localtime以及变成了一个链接文件 ``` [root@centos7 ...

  10. 【Codeforces Round #428 (Div. 2) B】Game of the Rows

    [Link]:http://codeforces.com/contest/839/problem/B [Description] 给你n排的如题目所示的位置; 同一排中(1,2) 算相邻; (3,4) ...