0

So, I have a child modal that I want to pass a DTO Object to as argument, the line would be such as:

 [routerLink]="['/', { outlets: { popup: 'apiDosageDialogFirstStep/'+ formDTO } }]"

I've learned the hard way that there is (or was) apparently no way to transfer complex objects via routerLink. However the reply I find mostly is like the one on this question, which is not useful to me as my object is a Data Transfer one and has no physical reference on a database to query for

So, I'd like to know if anyone has faced similar issue and what libraries / workarounds could suit best?

Steven
  • 1,236
  • 1
  • 13
  • 37

1 Answers1

1

I use ngrx as state management library, so everything is in central place. While navigating to outlet popup, I fetch dto from ngrx-store.

I hope this will help to you.

If you are not using ngrx then only way to get that DTO by subscribing DTO Object from service, I think it is said in the link that you given in question.

picciano
  • 22,341
  • 9
  • 69
  • 82
Borad Akash
  • 754
  • 1
  • 8
  • 21
  • Thanks! Yes I should probably learn about ngrx, about fetching from service, I fail to see how I would be able to do that. Where am I actually fetching the object from? It hasn't got a database representation and it's living in an encapsulated component which I haven't got a communication channel with, or have I? – Steven Jan 18 '18 at 15:28
  • You can use rxjs subject inside service and assign data to subject using rxjs next operator. and inside popup you can subscribe to that subject. You can find something usefull here: https://angular.io/guide/component-interaction#parent-and-children-communicate-via-a-service – Borad Akash Jan 18 '18 at 15:34
  • Thanks for that, had a go with the guide, setup a service, and I can send the DTO to it just fine, but I just can't get the subscribe method to work in the child. – Steven Jan 18 '18 at 18:10
  • are you using any library for modal popup implementation or is it you custom modal popup? – Borad Akash Jan 19 '18 at 04:55
  • Hi Borad, using ngb, however, I followed up this question with a new one: https://stackoverflow.com/questions/48328361/rxjs-subscribe-method-being-ignored Issue seems to be solved, I've upvoted and accepted your answer as it lead me in the right direction, thanks! – Steven Jan 19 '18 at 11:11