Answer the question
In order to leave comments, you need to log in
How to refresh page with Get parameter via router?
Please, prompt:
There is a project on Angular 2+, SPA.
There are entities, comments are attached to each entity.
The comment page for each entity has the /comment-list/123 address in the router, where 123 is the entity id.
On the same page there is a form for adding comments, after adding a comment, the list of comments on the page is supposed to be updated.
Tried to reload via
this.commentService.createComment(this.comment).subscribe(data => {
var id = Number.parseInt(activeRoute.snapshot.params["id"]);
this.router.navigate(['/comment-list', id]);
});
this.commentService.createComment(this.comment).subscribe(data => {
var id = Number.parseInt(activeRoute.snapshot.params["id"]);
this.router.navigateByUrl("/comment-list/" + id)
});
const appRoutes: Routes = [
...
{ path: 'comment-list/:id', component: CommentListComponent },
...
];
Answer the question
In order to leave comments, you need to log in
Reloading the page is not SPAshny at all)
You get data from the service, so tell him to re-request comments and not fight with the router.
There is a service in which a get and post request is made. There is a component which communicates with this service. In the component is done: It is
possible by handicraft
this.postRequest().subscribe( () => {
this.getRequest().subscibe( () => {
// ToDo
});
})
this.postRequest().subscribe( () => {
// ToDo
});
//----------
// Сервис
postRequest(...data) {
this.http.post(...).pipe(
switchMap( () => { // меняем поток на getRequest
return this.getRequest();
})
)
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question