angular - Angular Material MatDialog 不适用于 Angular-6
问题描述
我是 Angular/Angular 材料的初学者,我尝试使用MatDialog
我遵循了那个指令,但它对我不起作用吗? MatDialog-Overview
有人知道如何正确使用MatDialog
吗?
我的代码
<!--Add new button-->
<div class="d-flex flex-row-reverse bd-highlight">
<div class="p-2 bd-highlight"><button mat-flat-button class="btn-sg" color="primary" style=" width:200px; color: white " (click)="openDialog()" >+ Add New</button></div>
</div>
<!--/ End Add new button-->
.ts
import {MatDialog, MatDialogRef, MAT_DIALOG_DATA} from '@angular/material';
openDialog(): void {
const dialogRef = this.dialog.open(DialogOverviewExampleDialog, {
width: '250px',
data: {name: this.name, animal: this.animal}
});
dialogRef.afterClosed().subscribe(result => {
console.log('The dialog was closed');
this.animal = result;
});
}
谢谢
解决方案
您的 stackblitz 缺少对话框组件类。
import {Component, Inject} from '@angular/core';
import {MAT_DIALOG_DATA} from '@angular/material';
@Component({
selector: 'Dialogpge',
templateUrl: 'Dialogpge.html',
})
export class Dialogpge {
constructor(@Inject(MAT_DIALOG_DATA) public data: any) { }
}
有这个并将其导入 main.ts 和 dialog-overview-example.ts 文件。
这里(https://stackblitz.com/edit/angular-hxh2vi-unhrrq)是从您的版本分叉的 stackblitz 的工作版本
推荐阅读
- bash - 致命:使用 cron 作业推送到 git 时无法读取用户名
- python - 从数组中动态设置 QTableWidget 的内容
- laravel - 从 Ionic 登录记住我
- asp.net-mvc - 如何修复 System.FormatException:“输入字符串的格式不正确。”
- vb.net - 无法修复错误“无法加载 System.Net.Http,版本 = 4.2.0.0”
- c# - 使用命令行如何在 ASP.NET 中首先从 DB 搭建脚手架 - 而不是 ASP.NET Core MVC?
- php - 如何在 Laravel 的 UserController 中使用 2 个更新功能
- html - 如何使我的家谱树响应?
- xamarin.forms - Xamarin 离线位置 我们如何通过 GPS 获得离线位置?
- amcharts - amCharts,每条柱都有渐变色