gpt4 book ai didi

javascript - Angular Material 对话框打不开

转载 作者:行者123 更新时间:2023-12-05 08:54:14 25 4
gpt4 key购买 nike

我在使用 Angular Material 的对话框时遇到问题,当我按下按钮打开它时,它确实存在,但不是 rly。对话框不显示,但控制台打印“打开”和“关闭”,没有错误

对话框组件

import {Component, Inject} from '@angular/core';
import {RssFeed} from "../model/rssFeed";
import {MAT_DIALOG_DATA, MatDialogRef} from "@angular/material";
import {AppService} from "../service/app.service";

@Component({
selector: 'app-new-feed-dialog',
templateUrl: './new-feed-dialog.component.html',
styleUrls: ['./new-feed-dialog.component.css']
})
export class NewFeedDialogComponent {

rssFeed: RssFeed = new RssFeed();

constructor(private service: AppService,
public dialogRef: MatDialogRef<NewFeedDialogComponent>,
@Inject(MAT_DIALOG_DATA) public data: any) {
}

onSaveClick(): void {
this.service.saveRssFeed(this.rssFeed)
this.dialogRef.close(this.rssFeed);
}

onCancelClick(): void {
this.dialogRef.close();
}

}

html

<h2 mat-dialog-title>
<mat-icon>library_add</mat-icon>
New Feed
</h2>
<mat-dialog-content>
<form>
<mat-form-field class="full-width">
<input matInput placeholder="Feed Name" name="name" [(ngModel)]="rssFeed.name">
</mat-form-field>
<mat-form-field class="full-width">
<input matInput placeholder="Feed Url" name="url" [(ngModel)]="rssFeed.url">
</mat-form-field>
</form>
</mat-dialog-content>
<mat-dialog-actions>
<button mat-button (click)="onCancelClick()">Cancel</button>
<button mat-button (click)="onSaveClick()">Save</button>
</mat-dialog-actions>

我正在从另一个组件打开它

onAddRssFeedClick(): void{
let dialogRef = this.dialog.open(NewFeedDialogComponent)
dialogRef.afterOpen().subscribe( ()=> {
console.log('open')
})
dialogRef.afterClosed().subscribe(() => {
console.log('close')
});
}

最佳答案

在你的app.component.html , 有一个按钮可以触发你的模式 <a class="nav-link" (click)="onAddRssFeedClick()" href="#">Add Feed</a>

删除 href="#"你很好!

关于javascript - Angular Material 对话框打不开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50721917/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com