How can I add 2 inputs with one button into my backend?
Here is an example, I want that my User can write in my todo list, a task(string) and a sort of ID(number). And he can add these 2 inputs with the Button ADD:
Example Code:
<div id="main">
<h2 class="task-title">My Tasks</h2>
<div>
<form class="addTask">
<mat-form-field class="taskInput-widht">
<mat-label>Task name</mat-label>
<input matInput placeholder="Ex. Team meeting" maxlength="25" #taskName/>
</mat-form-field>
<mat-form-field class="taskIdInput-width">
<mat-label>Username ID</mat-label>
<input matInput placeholder="Ex. 1" #taskID/>
</mat-form-field>
<!--(click) passes input value to add() and then clears the input-->
<span class="addButton">
<button mat-raised-button color="primary" (click)="add(taskName.value); taskName.value=''">
ADD
</button>
</span>
</form>
</div>
I know that in this example I only send with the (click) the taskname.value to my backend, but the point is, I don't know how to do it with a second variable.
Add component method:
add(name: string): void {
this.taskService.addTask({name} as Task)
.subscribe(task => {
this.tasks.push(task);
});
}
Add service method:
/** POST: add a new task to the server */
addTask(task: Task): Observable<Task> {
return this.http.post<Task>(`${this.tasksUrl}/task`, task, this.httpOptions);
}
