Skip to content

Commit

Permalink
ngOnDestroy
Browse files Browse the repository at this point in the history
  • Loading branch information
clementolive committed Jul 9, 2023
1 parent 469a234 commit af7e892
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,4 @@
/.idea/modules.xml
/.idea/Proof_Of_Concept.iml
/.idea/vcs.xml
.idea/sonarlint/*
2 changes: 1 addition & 1 deletion frontend/src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const routes: Routes = [
];

@NgModule({
imports: [RouterModule.forRoot(routes)],
imports: [RouterModule.forRoot(routes, {onSameUrlNavigation: 'reload'})],
exports: [RouterModule]
})
export class AppRoutingModule { }
37 changes: 30 additions & 7 deletions frontend/src/app/pages/service-client/service-client.component.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Component } from '@angular/core';
import { Component, OnDestroy, OnInit } from '@angular/core';
import { FormBuilder, Validators } from '@angular/forms';
import { Router } from '@angular/router';
import { Observable } from 'rxjs';
import { NavigationEnd, Router } from '@angular/router';
import { Observable, Subscription } from 'rxjs';
import { Message } from 'src/app/interface/message';
import { MessageRequest } from 'src/app/payload/messageRequest';
import { MessageService } from 'src/app/service/message.service';
Expand All @@ -11,13 +11,23 @@ import { MessageService } from 'src/app/service/message.service';
templateUrl: './service-client.component.html',
styleUrls: ['./service-client.component.scss']
})
export class ServiceClientComponent {
export class ServiceClientComponent implements OnInit, OnDestroy{
constructor(private router: Router,
private messageService: MessageService,
private fb: FormBuilder) { }
private fb: FormBuilder) {

}

ngOnInit(): void {
//throw new Error('Method not implemented.');
this.router.routeReuseStrategy.shouldReuseRoute = function () {
return false;
};
}

// This is subscribed in DOM with async
public posts$: Observable<Message[]> = this.messageService.getMessages();
public sendingMessage$!: Subscription;

public form = this.fb.group({
content: ['',
Expand All @@ -28,10 +38,23 @@ export class ServiceClientComponent {
]
});



public submit(): void{
const request = this.form.value as MessageRequest;
request.author = "Utilisateur";
//const createpostRequest = this.form.value as Message;
this.messageService.sendMessage(request).subscribe();
this.sendingMessage$ = this.messageService.sendMessage(request).subscribe({
next: () =>{
//this.router.navigate(["ServiceClientComponent"]);
//this.sendingMessage$ = this.messageService.getMessages().subscribe();
window.location.reload();
}
});
}

ngOnDestroy(): void {
if(this.sendingMessage$) this.sendingMessage$.unsubscribe();
}


}

0 comments on commit af7e892

Please sign in to comment.