Rahul Gala
Rahul Gala

Reputation: 113

How do I connect two sibling components in Angular?

I have made one timer component and want to use it in two different places.

I want that if I start the timer at one place it should automatically start at the other and vice versa.

Using @Output and @ViewChild didn't work for me.

Upvotes: 0

Views: 58

Answers (3)

kup
kup

Reputation: 819

You can use state management or save time in localstorage and fetch the time from there. This way, you can show the time anywhere you want.

Upvotes: 1

Lakshman.S
Lakshman.S

Reputation: 101

For your use case, I prefer you to use NGRX Module in angular with Subject for Sibiling.

For more info, checkout this out https://ngrx.io/guide/store

Upvotes: 0

Eli Porush
Eli Porush

Reputation: 1557

You can store the time variable in a service (outside the timer component), and so, all instances of the component will use the same time...

Upvotes: 1

Related Questions