【发布时间】:2020-03-24 01:08:58
【问题描述】:
我有两个问题,第一个是我想用httpclient post方法向服务器发送数据,如果一切正常我想发送另一个post请求。我有第一个表(codeRole,nameRole)和第二个表(action,nameAction),用户可以以相同的形式创建一个角色并将这个角色链接到一个或多个动作,所有这些都注册在一个表 roleAction(id, codeRole, nameRole, action, nameAction),我不知道如何用 Angular 做到这一点,等待插入我的角色,然后在第三个表中一一插入角色操作。
我的代码可能是这样的:
<form
fxLayout="column"
fxFlexAlign="center center"
fxLayoutGap="10px"
#newRoleF="ngForm"
(ngSubmit)="onSubmitRoleF(newRoleF); newRoleF.resetForm({})"
[hidden]="!showRoleForm"
>
<!-- code role -->
<mat-label> Code Role</mat-label>
<mat-form-field>
<input
matInput
required
name="codeRole"
ngModel
>
</mat-form-field>
<!-- ******** fin code role *********** -->
<!-- nom role -->
<mat-label> Nom de role </mat-label>
<mat-form-field>
<input
matInput
required
name="nomRole"
ngModel
>
</mat-form-field>
<!-- ******** fin nom role *********** -->
<!-- Role actions -->
<mat-form-field>
<mat-label>Actions</mat-label>
<mat-select name="roleAction" ngModel multiple required>
<mat-option *ngFor="let action of droitActions" [value]="action">{{action.nom_action}}</mat-option>
</mat-select>
</mat-form-field>
<!-- ******** fin role actions *********** -->
<div fxLayout="row" fxLayoutGap="10px">
<button type="submit"
mat-raised-button
color="primary"
[disabled]="newRoleF.invalid"
>
Enregistrer
</button>
</div>
</form>
在 .ts 文件中
onSubmitRoleF(newRoleF: NgForm) {
const val = newRoleF.value;
const params = {};
params['code_role'] = val.codeRole;
params['nom_role'] = val.nomRole;
params['role_action'] = val.roleAction
// first add the role
this.droitsS.addRole(params)
.subscribe(
(resultat) => {
// once the role added, start to add the role actions one by one, if the user choose two
// actions, I must do two httpclient post to add them
},
(error => {
console.log(error);
})
);
感谢您的帮助
【问题讨论】:
标签: rxjs angular7 angular-httpclient