angular提交表格到php,Angular/aggrid:如何将行数据传递到表单?(材质对话框)

Example

,但我不知道如何正确地将数据传递到mat对话框。这是我的例子。首先,我有一个发出put请求的服务和另一个发布数据的服务:

editUser(employee: Employees) {

return this.http.put(this._url + '/' + employee.id, httpOptions).pipe(

map((res: Response) => res.json)

)

}

saveUser(employee: Employees) {

return this.http.post(this._url, employee, httpOptions).subscribe((res: any) => {

res = employee

this.componentMethodCallSource.next();

})

}

然后在我的

table.component

同学们,我有按钮的功能。这将选择行,调用服务,并打开对话框。

editUser() {

const selectRows = this.gridApi.getSelectedRows();

const editSub = selectRows.map((rowToEdit) => {

return this.service.editUser(rowToEdit);

});

this.openDialog(FormComponent)

}

ngoninit

. 这个条件决定了我是否

loadUser

MAT_DIALOG_DATA

加载json id,该id将确定

loadUsers()

应该被叫来。但我似乎无法访问我的id。我一直有一个错误,说它是

undefined

窗体组件

employeeInfo: Employees;

userId: number;

constructor(

public dialogRef: MatDialogRef,

private fb: FormBuilder,

private service: Service,

private http: HttpClient,

@Inject(MAT_DIALOG_DATA) public data: any

) {

this.userId = this.data.userId;

}

ngOnInit() {

this.createUserForm();

if (this.userId > 0) {

this.loadUser();

}

}

createUserForm() {

this.frmUser = this.fb.group({

id: [],

firstName: ["", [Validators.required]],

lastName: ["", Validators.required],

})

}

onSave() {

this.employeeInfo = this.frmUser.getRawValue();

this.employeeInfo.id = this.userId;

this.service.saveUser(this.employeeInfo)

this.dialogRef.close({

success: 'success',

data: {

emp: this.employeeInfo.id

}

})

}

loadUser() {

this.service.getData(this._url).subscribe((res: any) => {

this.frmUser.patchValue({

firstName: res.FirstName,

})

})

}

编辑:更新代码。仍无法将数据发送到表单:

表格组件:

editUser(user) {

const dialogRef = this.dialog.open(FormComponent, {

width: '250px',

data: user

});

dialogRef.afterClosed().subscribe(result => {

this.user = user;

});

}

constructor( public dialogRef: MatDialogRef,

private fb: FormBuilder, private service: Service, private http: HttpClient, @Inject(MAT_DIALOG_DATA) public data: Employees) {

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值