I would like to change my code towards a Reactive style, however I am struggling with the syntax when attempting to pass through parameters within the async pipe to an Observable
.
My current working code that is not Reactive (stydent.component.ts)
:
deleteStudent(id: number) {
this.uniCrudService.deleteStudent(id)
.subscribe( res => {
console.log(`deleteStudent: ${JSON.stringify(res)}`);
this.getStudents();
});
}
In my student.component.html
template I am calling the deleteStudent
like:
<a routerLink="" (click)="deleteStudent(student.id)">Delete</a>
The problem is that I need to use the async
pipe on an observable function that receives a parameter (for a Reactive style?).
For example:
deleteStudent(id: number): Observable<Student> {
return this.deleteStudent$ = this.uniCrudService.deleteStudent(id)
.pipe( tap (res => {
console.log(`deleteStudent: ${JSON.stringify(res)}`);
this.getStudents();
}));
and in the template:
<a routerLink="" (click)="deleteStudent(student.id) | async">Delete</a>
However this throws the error: Cannot have a pipe in an action expression
. Looking at this answer I am understanding that I cannot make this piece of my code Reactive, and I will be forced to keep the unwanted subscription
. Is this the case? How do I make my deleteStudent
Reactive and get rid of the subscription
?