angular material dialog应用
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应用的更多相关文章
- [转]Angular 4|5 Material Dialog with Example
本文转自:https://www.techiediaries.com/angular-material-dialogs/ In this tutorial, we're going to learn ...
- 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 ...
- Angular Material design设计
官网: https://material.io/design/ https://meterial.io/components 优秀的Meterial design站点: http://material ...
- [转]Angular4 引用 material dialog时自定义对话框/deep/.mat-dialog-container
本文转自:https://blog.csdn.net/qq_24078843/article/details/78560556 版权声明:本文为博主原创文章,未经博主允许不得转载. https://b ...
- Angular Material & Hello World
前言 Angular Material(下称Material)的组件样式至少是可以满足一般的个人开发需求(我真是毫无设计天赋),也是Angular官方推荐的组件.我们通过用这个UI库来快速实现自己的i ...
- 手势模型和Angular Material的实现
iPhone的出现让手势操作大为流行,也使得手势编程成为开发人员的挑战. 拟物设计也把手势编程纳入在内,大概也想制定一个在交互模型标准.现阶段因为MD还在预发布阶段,因此还只实现了单点手势(一个指头) ...
- 【转】Android新组件Material Dialog,SwipeRefreshLayout,ListPopupWindow,PopupMenu等
朝花夕拾----新组件的学习和使用 分类: Android UI2015-06-26 11:31 440人阅读 评论(0) 收藏 举报 uidialogMaterial 目录(?)[-] Mate ...
- Material使用11 核心模块和共享模块、 如何使用@angular/material
1 创建项目 1.1 版本说明 1.2 创建模块 1.2.1 核心模块 该模块只加载一次,主要存放一些核心的组件及服务 ng g m core 1.2.1.1 创建一些核心组件 页眉组件:header ...
- Angular Material 白天模式和黑夜模式
Material design调色板 https://www.materialpalette.com/ 明暗:虽然颜色不变,但是针对白天黑夜有做不同处理. 叠加:对话框,弹出菜单,事先是没有加载的.是 ...
随机推荐
- XML解析——SAX解析以及更方便的解析工具(JDOM、DOM4J)
XML主要用于数据交换,HTML则用于显示. 相对于DOM的树形解析,SAX采用的是顺序解析,这种解析方法可以快速地读取XML数据的方式. SAX主要事件: No. 方法 类型 描述 1 public ...
- 循环GridControl所有行
; i < gridView1.RowCount; i++) { DataRowView row = (DataRowView)gridView1.GetRow(i); } gridView1是 ...
- sql-server 2005数据库文件恢复(检測到基于一致性的逻辑 I/O 错误)
今天sql-server数据库突然报错: SQL Server 检測到基于一致性的逻辑 I/O 错误 校验和不对(应为: 0x7c781313,但实际为: 0x67a313c9). 在文件 'C:\P ...
- 洛谷P2891 [USACO07OPEN]吃饭Dining
题目描述 Cows are such finicky eaters. Each cow has a preference for certain foods and drinks, and she w ...
- 【基础篇】EditText的一些属性设置
设置EditText的背景颜色 private test_editText=null; test_editText= (EditText) findViewById(R.id.EditTextInp ...
- 【IOS学习】1.第一个IOS程序
1.执行原理 a.首先执行main函数 调用UIApplicationMain方法 return UIApplicationMain(argc, argv, nil, NSStringFromClas ...
- CString与 char *之间的转换
http://www.cnblogs.com/watsonlong/archive/2011/04/15/2017086.html
- Highcharts使用的一些总结
Highcharts 是一个用纯 JavaScript 编写的一个图表库, 能够很简单便捷的在 Web 网站或是 Web 应用程序添加有交互性的图表,并且免费提供给个人学习.个人网站和非商业用途使用. ...
- UVALive 5583 Dividing coins
Dividing coins Time Limit: 3000ms Memory Limit: 131072KB This problem will be judged on UVALive. Ori ...
- HTML中行内元素与块级元素有哪些及区别
二.行内元素与块级元素有什么不同? 块级元素和行内元素的区别是,块级元素会占一行显示,而行内元素可以在一行并排显示. 通过样式控制,它们可以相互转换. 1.尺寸-块级元素和行内元素之间的一个重要的不同 ...