I try to communicate between two component one which is dialog.component.ts and the other admin.component.ts with a service between them.
So in my dialog i have a form which triggered the service with the ngsubmit
collectSubmitForm(any) {
var myObj= new Object({form: any,typeOfForm: this.data.titleDialog});
this.dialogContentService.getCollectFormContent(myObj);
}
In my dialogService i have :
private dialogFormContent = new Subject<any>();
dialogFormContentUpdate$ = this.dialogFormContent.asObservable();
constructor() {
}
getCollectFormContent(dataAsParams) {
this.dialogFormContent.next(dataAsParams);
this.dialogFormContent = new Subject<any>();
}
and in my admin.component.ts i have : //Todo a revoir 2 call
constructor(private dialogService: DialogService) {
this.collectDataFromDialog();
}
collectDataFromDialog() {
this.subscription = this.dialogService.dialogFormContentUpdate$.subscribe(valueFromFormDialog => {
if(valueFromFormDialog){
this.subscriptionValueFromDialog = valueFromFormDialog;
this.anOtherFunction(this.subscriptionValueFromDialog)
}
});
}
ngOnDestroy() {
this.subscription.unsubscribe()
}
I don't know why the subscription is call two times