![](/img/trans.png)
[英]Passing the sensitive and long data from one component to another in Angular 2
[英]Angular material : passing data from one component to another
嗨 - 我有两个组件,第一个组件(ShowDepComponent)具有 ngFor 来收集“DapatmentName”和 DepartmentID”。 我想将这些“部门名称”传递给另一个组件(AddEditDepComponent)。 当触发点击事件时,DepartmentName 应该传递给另一个组件(AddEditDepComponent)。 怎么做? 谢谢。
显示深度组件:
html:
... ... <ng-container *ngFor="let eachone of GetDepartList"> <mat-grid-tile [style.background]="'#F1EBBA'"> {{eachone.DepartmentId}} <mat-grid -tile [(ngModel)]="DepartmentName" [style.background]="'#F1EBBA'"> {{eachone.DepartmentName}} <mat-grid-tile [style.background]="'#F1EBBA'"> <button (click) = "EditDeprt()" class="Options" mat-stroked-button> 编辑 <button (click) = "DelDeprt()" mat-stroked-button> 删除在此处输入代码
.ts 文件:
.. .. 部门名称:任何; 部门:任何; EditDeprt() { this.Dialog.open(AddEditDepComponent, { height: '200px', width: '400px', data: {DepartmentName: this.DepartmentName} })
到目前为止您所做的是正确的,剩下的唯一事情就是在您的AddEditDepComponent
中获取Department
名称。
因此,在您的AddEditDepComponent
中,您可以将您从ShowDepComponent
发送的数据注入其构造函数。 您已经使用dialog.open()
方法发送了数据。
您所要做的就是在AddEditDepComponent
.ts 中获取该数据:
constructor(
@Inject(MAT_DIALOG_DATA) public data: any,
){}
ngOnInit(): void {
console.log(this.data.DepartmentName);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.