I finally know how to do that. Here's how I'm doing it. First I make the data model
Data Model
export class ActivityLogDataSend {
startDate: string = "";
endDate: string = "";
tableName: string = "";
columnName: string = "";
remarks: string = "";
}
Then I make the FormGroup and FormControl to input the data
Code
this.activityLogForm = this.formBuilder.group({
startDate: new FormControl({
value: this.data.startDate ? "" : this.data.startDate,
disabled: this.mode === EditMode.view || this.mode === EditMode.edit
}, [Validators.required]),
endDate: new FormControl({
value: this.data.endDate ? "" : this.data.endDate,
disabled: this.mode === EditMode.view || this.mode === EditMode.edit
}, [Validators.required]),
tableName: new FormControl({
value: this.data.tableName ? "" : this.data.tableName,
disabled: this.mode === EditMode.view || this.mode === EditMode.edit
}, [Validators.required]),
columnName: new FormControl({
value: this.data.columnName ? "" : this.data.columnName,
disabled: this.mode === EditMode.view || this.mode === EditMode.edit
}, [Validators.required]),
remarks: new FormControl({
value: this.data.remarks ? "" : this.data.remarks,
disabled: this.mode === EditMode.view || this.mode === EditMode.edit
}, [Validators.required]),
});
After that I just make some simple button using Angular material, and create class to call the API and get the data.
Call API
getData(event): void {
const sb = this.activityLogSvc.getData(this.activityLogForm.getRawValue()).subscribe((result) => {
this.displayedData = result;
console.log(JSON.parse(result.syncData), 'JINX');
});
this.subscriptions.push(sb);
}
And that's how to insert data to API using Angular 11.