Javascript 单击div角度7上的Pass Value onclick
我有一个具有点击功能的div。我想在单击时将值传递给材质对话框。我知道如何在输入上使用ngModal。我不知道怎么做。有什么想法吗?谢谢 HTML: 这是我的情态:Javascript 单击div角度7上的Pass Value onclick,javascript,html,angular,typescript,angular-material,Javascript,Html,Angular,Typescript,Angular Material,我有一个具有点击功能的div。我想在单击时将值传递给材质对话框。我知道如何在输入上使用ngModal。我不知道怎么做。有什么想法吗?谢谢 HTML: 这是我的情态: @Component({ selector: "popup-dialog", templateUrl: "./popupDialog.component.html" }) export class PopupDialog { constructor(public dialogRef: MatDialogRef<PopupDia
@Component({
selector: "popup-dialog",
templateUrl: "./popupDialog.component.html"
})
export class PopupDialog {
constructor(public dialogRef: MatDialogRef<PopupDialog>) {}
onNoClick(): void {
this.dialogRef.close();
}}
@组件({
选择器:“弹出对话框”,
templateUrl:“./popupDialog.component.html”
})
导出类弹出对话框{
构造函数(public dialogRef:MatDialogRef){}
onNoClick():void{
this.dialogRef.close();
}}
更改您的openDialog
函数并在数据中传递值
:
openDialog(value): void {
const dialogRef = this.dialog.open(PopupDialog, {
data: { x: value },
});
dialogRef.afterClosed().subscribe(_result => {
console.log('The dialog was closed');
});
}
现在,在PopupDialog组件中,您可以在构造函数中插入MAT\u DIALOG\u数据
,以访问传递的值,如下所示:
@Component({
selector: "popup-dialog",
templateUrl: "./popupDialog.component.html"
})
export class PopupDialog {
x: any;
constructor(
public dialogRef: MatDialogRef<PopupDialog>,
@Inject(MAT_DIALOG_DATA) public data: any
) {
// here the received value is being assigned to class variable `x`
this.x = data.x;
}
onNoClick(): void {
this.dialogRef.close();
}
}
@组件({
选择器:“弹出对话框”,
templateUrl:“./popupDialog.component.html”
})
导出类弹出对话框{
x:任何;
建造师(
公共dialogRef:MatDialogRef,
@注入(MAT_对话框_数据)公共数据:任意
) {
//这里,接收到的值被分配给类变量`x`
这个.x=数据.x;
}
onNoClick():void{
this.dialogRef.close();
}
}
有关更多选项和详细文档:Awesome。成功了。非常感谢。
openDialog(value): void {
const dialogRef = this.dialog.open(PopupDialog, {
data: { x: value },
});
dialogRef.afterClosed().subscribe(_result => {
console.log('The dialog was closed');
});
}
@Component({
selector: "popup-dialog",
templateUrl: "./popupDialog.component.html"
})
export class PopupDialog {
x: any;
constructor(
public dialogRef: MatDialogRef<PopupDialog>,
@Inject(MAT_DIALOG_DATA) public data: any
) {
// here the received value is being assigned to class variable `x`
this.x = data.x;
}
onNoClick(): void {
this.dialogRef.close();
}
}