作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个带有输入字段的底部表格和两个按钮提交和取消。
父组件 HTML
<div class="something" (click)="openBottomSheet()"></div>
import { MatBottomSheet } from "@angular/material";
constructor(private bottomsheet: MatBottomSheet) { }
openBottomSheet(): void {
this.bottomsheet.open(BottomsheetComponent);
}
<mat-form-field>
<input type="password" matInput placeholder="Password" [formControl]="password">
</mat-form-field>
<button mat-button (click)="closeBottomSheet()">Cancel</button>
<button mat-button (click)="checkPassword()">Confirm Password</button>
import { MatBottomSheetRef } from "@angular/material";
constructor(private bottomsheet: MatBottomSheetRef<BottomsheetComponent>){}
closeBottomSheet(){
this.bottomsheet.dismiss();
}
checkPassword(){
//Here I need to pass data to parent component
}
最佳答案
您可以使用底部工作表引用及其提供的可观察对象。我使用了内联注释来获取更多详细信息。
您可以在此处找到有关底片的更多详细信息- https://material.angular.io/components/bottom-sheet/overview
// Parent component
import { MatBottomSheet } from "@angular/material";
constructor(private bottomsheet: MatBottomSheet) { }
openBottomSheet(): void {
// Take refernce of bottom sheet
const bottomSheetRef = this.bottomsheet.open(BottomsheetComponent);
// subscribe to observable that emit event when bottom sheet closes
bottomSheetRef.afterDismissed().subscribe((dataFromChild) => {
console.log(dataFromChild);
});
}
// Child component
import { MatBottomSheetRef } from "@angular/material";
constructor(private bottomsheet: MatBottomSheetRef<BottomsheetComponent>){}
closeBottomSheet(){
// pass the data to parent when bottom sheet closes.
this.bottomsheet.dismiss(data);
}
checkPassword(){
//Here I need to pass data to parent component
}
关于angular - 如何将数据从 MatBottomSheet 返回到其父组件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60359019/
我是一名优秀的程序员,十分优秀!