Whenever I change the value in the radio button within a form popup, I want to trigger this action. Below is the corresponding HTML code:
<ng-container cdkColumnDef="injected">
<mat-header-cell *cdkHeaderCellDef class="radioButtonVacXin"&g t;>
<p style="width:50px;"&g t;
{{'VacXin.Injected' | translate}}
</p>
<p>
{{'VacXin.notInjected' | translate}}
</p>
<p>
{{'VacXin.refuseInjected' | translate}}
</p>
</mat-header-cell>
& lt;mat-cell *cdkCellDef= "let item" class= "radioButtonVacXin"&g t;>
<mat-radio-group class= "w-180" class= "radioButtonVacXin" fxLayout="row" [(ngModel)]= "item.injected" [ ngModelOptions]= "{standalone: true}"&g t;>
<mat-radio-button class= "w-60" [value]= "1" fxLayoutAlign= "center center"&g t;
</mat-radio-button>
<mat-radio-button class= "w-60" [value]= "0" fxLayoutAlign= "center center"&g t;
</mat-radio-button>
<mat-radio-button class= "w-60" [value]= "2" fxLayoutAlign= "center center"&g t;
</mat-radio-button>
</mat-radio-group& g t;
</mat-cell>
</ng -container>
Additionally, here is how my TypeScript file appears:
export class AddStaffVacXinComponent implements OnInit {
item: any = {};
form: FormGroup;
formErrors: any;
isEdit: boolean;
comboData: any[] = [];
allManufactory: any[] = [];
FilterManufactory: any[] = [];
displayedVacXin = ['injected'];
params: any = {};
dataSourceVacXin: MatTableDataSource< any> = new MatTableDataSource< any>([]);
employeeId : any ={};
constructor(
public snackBar: MatSnackBar,
private translate: TranslatePipe,
public staffVacXin: StaffVacxinService,
public dialogRef: MatDialogRef< AddStaffVacXinComponent>,
@Inject( MAT_DIALOG_DATA) public data: any,
public dialog: MatDialog,
private formBuilder: FormBuilder,
) {
if (this.data.item) {
this.item = Object.assign({ }, data.item);
this.employeeId = this.item.id;
this.isEdit = true;
}
else {
this.isEdit = false;
}
}
ngOnInit() {
let params = this.params;
this.params = this.employeeId;
this.staffVacXin.getDetail(this.params).then(res => {
debugger
this.dataSourceVacXin.data = res;
});
}
processResponse(res) {
if (res) {
this.snackBar.open(
this.translate.transform("Common.Msg.UpdateSuccess"),
"OK",
{
verticalPosition: "top",
duration: 2000,
}
);
this.dialogRef.close(res);
} else {
this.snackBar.open(
this.translate.transform("Common.Msg.UpdateError"),
"OK",
{
verticalPosition: "top",
duration: 2000,
}
);
}
}
save() {
debugger
if (!this.data.isEdit) {
this.staffVacXin.post(this.item).then(rs => {
if (rs) {
this.processResponse(true);
} else {
this.processResponse(false);
}
})
} else {
this.staffVacXin.put(this.item, this.item.id).then(rs => {
if (rs) {
this.processResponse(true);
} else {
this.processResponse(false);
}
})
}
}
Furthermore, the API response is structured as follows; where inject=0 corresponds to "notInjected", inject=1 represents "Injected", and inject=3 signifies "refuseInjected". The data is fetched based on the employeeId, and I intend to trigger certain actions when the form values are changed.
[
{
"name": "HEBERBIOVAC",
"inject": 1,
"note": "namhg",
"employeeId": "7f11a477-e672-439c-a40c-acfa14d8122f",
"vaccinId": "a41f12e5-7e67-45b8-a344-08dacdf4156b"
},
{
"name": "PRIORIX",
"inject": 0,
"note": "namhg",
"vaccinId": "5d0546dc-cdc0-4629-a345-08dacdf4156b",
"employeeId": "7f11a477-e672-439c-a40c-acfa14d8122f"
},
{
"name": "nnn",
"inject": 0,
"note": "test",
"vaccinId": "8ab9a6b9-b956-462e-a346-08dacdf4156b",
"employeeId": "7f11a477-e672-439c-a40c-acfa14d8122f"
}
]