0

I am making an app with Angular 2 where i have two components each having its own EventEmitter. One EventEmitter is fired when bunch of checkboxes are checked/unchecked and the other is fired when a search keyword is entered. The search bar is in the header component and the checkboxes are in different component.

I am able to catch these eventEmitters separately - however i want to combine their data into URL params.

For example: http://localhost:4200;data=a123,b345,c678;q=searchkeyword

The data values should come from checkboxes and the q from a search bar.

I cant seem to find a way to append to the URL params data and keyword provided separately.

Can someone please suggest to me how i should do this?

Hassan
  • 2,308
  • 5
  • 21
  • 31

1 Answers1

0

if you mean that you need to wait for both events will be fired I would suggest to use observable . with the zip operator: http://reactivex.io/documentation/operators/zip.html

almog
  • 798
  • 1
  • 7
  • 18
  • Well, both events can fire on different times. But they need to not override each other. One event sends the `data` values while the other sends `searchkeyword`. I need to build the URL based on their values. For example, if i check two checkboxes, the url will change. Then later on i enter a keyword in the search field, that too should be appended in the URL (not overriding the values set by checkboxes). I hope this makes the question little more clear :) – Hassan Aug 22 '16 at 06:34
  • So the use of observables is exactly what you need. make observable for ant event you want to listren to, subscribe to all the events with merge operator. http://reactivex.io/documentation/operators/merge.html merge will fit you better then zip. – almog Aug 23 '16 at 06:57