我刚开始学习Angular 5,我只需要在单击按钮时打开一个对话框。应用程序无法构建,我遇到的错误是“错误ts2339:类型Dashboardcomponent上不存在属性对话框”。
然后我安装了angular material和cdk。编译时仍然出现相同的错误。并且在html页面(localhost:4200)上,我得到的错误是“无法读取未定义的'open'属性”。如何在angular上使对话框和打开功能正常工作?
typscript:
typscript:
import { Component, OnInit } from '@angular/core';
import { WebapiService } from '../providers/webapi.service';
import { MatDialog, MatDialogRef } from '@angular/material';
import { ServerDialogComponent } from '../server-dialog/server-dialog.component';
@Component({
selector: 'app-dashboard',
templateUrl: './dashboard.component.html',
styleUrls: ['./dashboard.component.scss']
})
export class DashboardComponent implements OnInit {
constructor(private webApi: WebapiService) { }
ngOnInit() {
}
openServerDialog() {
const serverDialogRef = this.dialog.open(ServerDialogComponent, {
width: '250px',
data: { serverlist: this.webApi.getServerList() }
});
}
}
html:
<div class="main-content">
<div class="container-fluid">
<button mat-fab color="warning" (click)="openServerDialog()">open</button>
</div>
</div>